Add warning about using UUIDs with activestorage #36562
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When using ActiveStorage against models that have a UUID as their primary key the underlying attachment references are broken and random files get returned when fetching the attachment.
A question on stackoverflow that describes this problem in more detail can be found for example at https://stackoverflow.com/questions/51531441/rails-5-2-activestorage-with-uuids-on-postgresql
This PR just adds a warning / headsup comment on the corresponding guide.
Additionally I think it should be considered to file this as a bug, activestorage should never return seemingly random files potentially uploaded by other users due to this - instead I think it would make sense to raise an exception when trying to make the attachment against a model that has a different column type.
However, I think this tiny addition can already be helpful to users so I'd like to propose this addition, if I should also prepare a bug report for the more general issue please let me know.
Thanks!