@@ -783,6 +783,17 @@ function scalarFk(value: unknown): string | null {
783783 return null ;
784784}
785785
786+ /**
787+ * A supplied FK value that names SOMETHING but not as a scalar id — an object
788+ * such as `{ id }`, or an array. The guard cannot tell which master it names
789+ * and does not rely on a later step unwrapping it, so the write is judged as
790+ * unresolved (fail closed), never as touching no master (L1-a R2, #35755).
791+ */
792+ function unscalarFk ( value : unknown ) : boolean {
793+ if ( value === undefined || value === null || value === '' ) return false ;
794+ return scalarFk ( value ) === null ;
795+ }
796+
786797/**
787798 * Bind the DETAIL-ROW lock (ruling A on the record-page edit card,
788799 * 「一起锁」): while a master record is held by a LOCKING pending approval, its
@@ -850,6 +861,7 @@ export function bindDetailRowLockHook(
850861 for ( const e of edges ) {
851862 const id = scalarFk ( data [ e . fk ] ) ;
852863 if ( id ) touched . push ( { master : e . master , id } ) ;
864+ else if ( unscalarFk ( data [ e . fk ] ) ) unresolved = true ;
853865 }
854866 } else {
855867 let previous = ctx ?. previous as Record < string , unknown > | undefined ;
@@ -875,6 +887,7 @@ export function bindDetailRowLockHook(
875887 if ( event === 'update' && Object . prototype . hasOwnProperty . call ( data , e . fk ) ) {
876888 const after = scalarFk ( data [ e . fk ] ) ;
877889 if ( after && after !== before ) touched . push ( { master : e . master , id : after } ) ;
890+ else if ( unscalarFk ( data [ e . fk ] ) ) unresolved = true ;
878891 }
879892 }
880893 }
@@ -883,6 +896,18 @@ export function bindDetailRowLockHook(
883896 const exempt = ( pending : any ) =>
884897 ! ! writerRun && ! ! pending ?. flow_run_id && String ( writerRun ) === String ( pending . flow_run_id ) ;
885898
899+ // The end-user sentence naming the MASTER object (the record lock's own).
900+ const sentenceFor = ( master : string ) : string => {
901+ let schema : unknown ;
902+ try { schema = engine . getSchema ?.( master ) ; } catch { /* registry unavailable — label degrades */ }
903+ const declaredLabel = typeof ( schema as any ) ?. label === 'string' && ( schema as any ) . label
904+ ? String ( ( schema as any ) . label )
905+ : undefined ;
906+ const { locale, service, translate } = refusalLocalization ( ctx , i18nService ) ;
907+ const masterLabel = readerLabelsFor ( service , locale ) ?. objectLabel ( master ) ?? declaredLabel ;
908+ return recordLockRefusal ( masterLabel , undefined , locale , translate ) ;
909+ } ;
910+
886911 // Fail closed on a write whose rows could not be named: refused when any
887912 // record of any master is held by a locking approval.
888913 if ( unresolved ) {
@@ -893,6 +918,7 @@ export function bindDetailRowLockHook(
893918 lockedError (
894919 `cannot determine which '${ e . master } ' record a ${ event } on its detail object '${ object } ' falls under, ` +
895920 `and ${ locking . length } record(s) of '${ e . master } ' carry a locking pending approval, so the write is refused` ,
921+ sentenceFor ( e . master ) ,
896922 ) ;
897923 }
898924 }
@@ -901,18 +927,11 @@ export function bindDetailRowLockHook(
901927 for ( const { master, id } of touched ) {
902928 const locking = ( await lockingRequestsForRecords ( engine , master , [ id ] ) ) . filter ( ( p ) => ! exempt ( p ) ) ;
903929 if ( locking . length === 0 ) continue ;
904- let schema : unknown ;
905- try { schema = engine . getSchema ?.( master ) ; } catch { /* registry unavailable — label degrades */ }
906- const declaredLabel = typeof ( schema as any ) ?. label === 'string' && ( schema as any ) . label
907- ? String ( ( schema as any ) . label )
908- : undefined ;
909- const { locale, service, translate } = refusalLocalization ( ctx , i18nService ) ;
910- const masterLabel = readerLabelsFor ( service , locale ) ?. objectLabel ( master ) ?? declaredLabel ;
911930 logger ?. info ?.(
912931 `[approvals] ${ event } on detail object '${ object } ' refused RECORD_LOCKED: its master '${ master } ' ` +
913932 `record '${ id } ' is held by pending approval request '${ String ( locking [ 0 ] ?. id ?? '' ) } '` ,
914933 ) ;
915- const sentence = recordLockRefusal ( masterLabel , undefined , locale , translate ) ;
934+ const sentence = sentenceFor ( master ) ;
916935 lockedError ( sentence , sentence ) ;
917936 }
918937 } ;
0 commit comments