@@ -31,6 +31,7 @@ import {
3131import { validateAdlibTestingPartInstanceProperties } from '../playout/adlibTesting'
3232import { ReadonlyDeep } from 'type-fest'
3333import { convertIngestModelToPlayoutRundownWithSegments } from './commit'
34+ import { PlayoutRundownModel } from '../playout/model/PlayoutRundownModel'
3435
3536type PlayStatus = 'previous' | 'current' | 'next'
3637type SyncedInstance = {
@@ -131,12 +132,22 @@ export async function syncChangesToPartInstances(
131132 pieceInstances : pieceInstancesInPart . map ( ( p ) => convertPieceInstanceToBlueprints ( p . pieceInstance ) ) ,
132133 }
133134
135+ const part = newPart ?? existingPartInstance . partInstance . part
136+
137+ let playoutRundownModelForPart : PlayoutRundownModel | undefined = playoutRundownModel
138+ // Handle a case where the part is in a different rundown than the playoutRundownModel:
139+ if ( playoutRundownModel . rundown . _id !== part . rundownId ) {
140+ playoutRundownModelForPart = playoutModel . getRundown ( part . rundownId )
141+ }
142+ if ( ! playoutRundownModelForPart )
143+ throw new Error ( `Internal Error: playoutRundownModelForPart is undefined (it should never be)` )
144+
134145 const proposedPieceInstances = getPieceInstancesForPart (
135146 context ,
136147 playoutModel ,
137148 previousPartInstance ,
138- playoutRundownModel ,
139- newPart ?? existingPartInstance . partInstance . part ,
149+ playoutRundownModelForPart ,
150+ part ,
140151 await piecesThatMayBeActive ,
141152 existingPartInstance . partInstance . _id
142153 )
@@ -211,10 +222,11 @@ export async function syncChangesToPartInstances(
211222 // TODO - these dont get shown to the user currently
212223 // TODO - old notes from the sync may need to be pruned, or we will end up with duplicates and 'stuck' notes?+
213224 existingPartInstance . appendNotes ( newNotes )
214-
215- validateAdlibTestingPartInstanceProperties ( context , playoutModel , existingPartInstance )
216225 }
217226
227+ // Make sure an adlib-testing part is still labeled correctly. This could happen if the partInstance used any recently updated adlibs
228+ validateAdlibTestingPartInstanceProperties ( context , playoutModel , existingPartInstance )
229+
218230 if ( existingPartInstance . partInstance . _id === playoutModel . playlist . currentPartInfo ?. partInstanceId ) {
219231 // This should be run after 'current', before 'next':
220232 await syncPlayheadInfinitesForNextPartInstance (
0 commit comments