Hi Kevin,
I found this (I'm a rusty Oracle DBA). I'm not disputing that attaching the same file to any number of objects normally works fine. That's true, and it's actually because of a second, correct unique key (file-type: object_id, file_id, type) that does exactly that job properly.
The edge case is narrower than "attach a file twice": it only triggers when two different object types (e.g. a Canned Response and an FAQ) happen to land on the same numeric row ID by coincidence — since canned_id and faq_id are independent AUTO_INCREMENT counters, that's rare, but not impossible on any install with enough of both. file_object's key (file_id, object_id) doesn't include type, so it can't tell those two rows apart and throws a false duplicate.
This isn't theoretical for us — we hit it for real during a from-scratch dev rebuild, where a Canned Response and an FAQ both happened to land on id 19: Duplicate entry '9-19' for key 'attachment.file_object'
Traced it through include/upgrader/streams/core/: file_object was added in the v1.11.0 patch as a plain, non-unique INDEX (performance only). No later patch ever converts it to UNIQUE — but the current shipped install-mysql.sql has it as UNIQUE KEY anyway. Looks like unintentional drift in the fresh-install schema snapshot, not a deliberate change.
We applied the fix (DROP KEY file_object, leaving file-type untouched) to both our dev and production databases and verified two things directly afterward: (1) the original collision now succeeds, (2) a genuine duplicate (same file+object+type) is still correctly rejected by file-type. No adverse effects since.
Happy to share the exact repro script if useful for a fix upstream.
Thanks!