cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Cannot change directly folder for media with associated data

phoude
Participant
0 Kudos
1,051

Hi,

I am encountering the below exception when trying to sync a specific media object that has changed folder. The only way I was able to get around this is by deleting the media object in the online catalog.

 

25.10.09 18:45:36:951 INFO Starting synchronization ...
25.10.09 18:45:37:331 ERROR Trying to change folder for media AcmeReportingDocument which has associated data
25.10.09 18:45:37:331 ERROR error setting partOf attribute folder : de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.media.interceptors.PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor@943405e]:Cannot change directly folder for media with associated data!
de.hybris.platform.catalog.SynchronizationPersistenceException: de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.media.interceptors.PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor@943405e]:Cannot change directly folder for media with associated data!
at de.hybris.platform.catalog.synchronization.ServiceLayerSynchronizationPersistenceAdapter.doUpdate(ServiceLayerSynchronizationPersistenceAdapter.java:391)
at de.hybris.platform.catalog.synchronization.ServiceLayerSynchronizationPersistenceAdapter.update(ServiceLayerSynchronizationPersistenceAdapter.java:356)
at de.hybris.platform.catalog.synchronization.ServiceLayerSynchronizationPersistenceAdapter.update(ServiceLayerSynchronizationPersistenceAdapter.java:51)
at de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreator.setReferenceAttribute(ItemCopyCreator.java:848)
at de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreator.setReferenceAttributesWaitingOnDelay(ItemCopyCreator.java:780)
at de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreator.setOtherReferences(ItemCopyCreator.java:743)
at de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreator.doCopy(ItemCopyCreator.java:469)
at de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreator$2.execute(ItemCopyCreator.java:429)
at de.hybris.platform.tx.Transaction.execute(Transaction.java:1289)
at de.hybris.platform.tx.Transaction.execute(Transaction.java:1207)
at de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreator.doCopyInTx(ItemCopyCreator.java:422)
at de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreator.copy(ItemCopyCreator.java:246)
at de.hybris.platform.catalog.jalo.synchronization.GenericCatalogCopyContext.copy(GenericCatalogCopyContext.java:2360)
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncCopyContext.copy(CatalogVersionSyncCopyContext.java:529)
at de.hybris.platform.catalog.jalo.synchronization.GenericCatalogCopyContext.copy(GenericCatalogCopyContext.java:2285)
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncWorker.copyItem(CatalogVersionSyncWorker.java:182)
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncWorker.doSynchronization(CatalogVersionSyncWorker.java:153)
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncWorker$1.run(CatalogVersionSyncWorker.java:116)
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncMaster.runExclusiveIfNecessary(CatalogVersionSyncMaster.java:305)
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncWorker.run(CatalogVersionSyncWorker.java:89)
at java.base/java.lang.Thread.run(Thread.java:840)
at de.hybris.platform.core.threadregistry.RegistrableThread.internalRun(RegistrableThread.java:134)
at de.hybris.platform.catalog.jalo.synchronization.CatalogVersionSyncWorkerThread.internalRun(CatalogVersionSyncWorkerThread.java:71)
at de.hybris.platform.core.threadregistry.RegistrableThread.run(RegistrableThread.java:124)
Caused by: de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.media.interceptors.PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor@943405e]:Cannot change directly folder for media with associated data!
at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.invokeValidateInterceptors(ModelWrapper.java:303)
at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.validate(ModelWrapper.java:240)
at de.hybris.platform.servicelayer.internal.model.extractor.impl.DefaultModelExtractor.process(DefaultModelExtractor.java:50)
at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.performPersistenceOperations(DefaultModelService.java:708)
at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAllInternal(DefaultModelService.java:703)
at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAll(DefaultModelService.java:683)
at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.save(DefaultModelService.java:630)
at de.hybris.platform.catalog.synchronization.ServiceLayerSynchronizationPersistenceAdapter$5.executeWithoutResult(ServiceLayerSynchronizationPersistenceAdapter.java:384)
at de.hybris.platform.servicelayer.session.SessionExecutionBody.execute(SessionExecutionBody.java:21)
at de.hybris.platform.servicelayer.session.impl.DefaultSessionService.executeInLocalView(DefaultSessionService.java:82)
at de.hybris.platform.catalog.synchronization.ServiceLayerSynchronizationPersistenceAdapter.doUpdate(ServiceLayerSynchronizationPersistenceAdapter.java:375)
... 23 more
Caused by: de.hybris.platform.servicelayer.interceptor.InterceptorException: [de.hybris.platform.media.interceptors.PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor@943405e]:Cannot change directly folder for media with associated data!
at de.hybris.platform.media.interceptors.PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor.onValidate(PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor.java:70)
at de.hybris.platform.media.interceptors.PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor.onValidate(PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor.java:26)
at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.invokeValidateInterceptors(ModelWrapper.java:292)
... 33 more

 

Accepted Solutions (1)

Accepted Solutions (1)

balaji_k1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Dear phoude,

If you attempt to change the media folder directly when a media object already has associated data, the system can lose track of the object's actual location. If this is the case, the following consequences can occur:
  • The original data becomes abandoned, remaining in the media storage but no longer accessible to the system

  • The abandoned data is not removed or modified by deleting or updating a corresponding media entry, wasting storage space and preventing proper cleanup

To avoid these issues, the project.properties file includes a dedicated configuration property: media.folder.directFolderChangeGuard.enabled, set to true

With this default setting in place, whenever an action is performed on a media object, a related interceptor (PreventDirectFolderChangeForNonEmptyMediaValidateInterceptor) is activated

Caution

If you need to disable this protection, you can set media.folder.directFolderChangeGuard.enabled to false. However, this action is strongly discouraged as it risks the issues described above

The global guard is supplemented by a second line of defense: the session attribute allowDirectMediaFolderChange. You can use this attribute to temporarily bypass the guard for specific operations, allowing direct folder changes for media. The default setting is false. Changing the value to true explicitly allows direct folder changes, but only for the current session.

The system throws an InterceptorException, preventing the direct folder change, when the checks confirm that all the following conditions are met:
  • The media.folder.directFolderChangeGuard.enabled is true (default)
  • The allowDirectMediaFolderChange is false (default)
  • The MediaFolder reference has changed
  • The existing media has associated data
Note

The validation logic doesn't impose any restrictions on the creation of new media items. It's only applied when an existing media item with associated data is being moved to a different folder, and the direct folder change is not specifically allowed for the session

Also refer to this KBA 3607303 - Cannot change directly folder for media with associated data

phoude
Participant
0 Kudos
Hi, thanks for the detailed answer. When I try to click on the link then I get a message back saying that the KB hasn't released yet. Since this situation happens during a sync then I wonder why the sync process is not gracefully handling this situation. When changing the media folder in backoffice, there is a "Move Media" button that you have to click. The related backend code could be invoked during the sync process and handle the target media in that way.

Answers (0)