- 🇳🇿New Zealand ericgsmith
I can reliable reproduce this issue - and it is caused by static caching in
file_get_file_references
.When editing via the UI here is what is happening:
- FormBuilder gets the values from all inputs
- The managed file widget checks
$file->access('download')
in\Drupal\file\Element\ManagedFile::valueCallback
- If the file is private then the file access control calls
file_get_file_usage
to determine access. At this point, the save is not complete on the from so the current references are cached in file_get_file_usage. - Then the entity is saved, this module calls
file_get_file_usage
and gets bad / outdated data
That check was introduced in SA-CORE-2020-011 so its probably need broken since then.
Hence - if the file is public then it is correctly moved to private as nothing is cached but it if is private then file_get_file_usage has cached (incorrect) data in it when this module runs.
The issue is core - file_get_file_usage is statically caching stuff.
https://www.drupal.org/project/drupal/issues/3035352 📌 [PP-1] Deprecate file_get_file_references(). Move the logic to file.usage service Postponed is where this would be solved by using a memory cache bin in the new service that is cache tag aware... But... its postponed.
I have half baked patch for core that demonstrates the issue - I'll add it to 3035352.
- 🇩🇪Germany geek-merlin Freiburg, Germany
Thx eric for researching and closslinking this!
Can you put your work in a dedicated issue (instead of hijacking the other)? Feel free to ping me, so i can review and RTBC it.