Skip to content

fix(preview): qualify the ambiguous columns in PreviewMapper queries - #63286

Open
solracsf wants to merge 1 commit into
masterfrom
fix/preview-mapper-query-correctness
Open

fix(preview): qualify the ambiguous columns in PreviewMapper queries#63286
solracsf wants to merge 1 commit into
masterfrom
fix/preview-mapper-query-correctness

Conversation

@solracsf

@solracsf solracsf commented Aug 15, 2026

Copy link
Copy Markdown
Member

Summary

joinLocation() joins previews (p) with preview_locations (l) and preview_versions (v). Both previews and preview_versions have a file_id column, so any unqualified file_id condition is ambiguous and MySQL or MariaDB reject the query with error 1052.

getPreviewForSpecification() built its conditions straight from the caller's array keys, so this broke every preview save: savePreview() uses that lookup to recover the existing row after a unique constraint violation. getByFileId() had the same unqualified condition, while getAvailablePreviewsForFile() next to it already used p.file_id.

Columns that come from the joined tables keep resolving to their own alias, and keys that already carry one are passed through untouched, so a caller can still filter on v.version.

The values are bound with an explicit type as well. An untyped false binds as an empty string, which PostgreSQL rejects for a boolean column, so qualifying the columns on their own only moved the error on that backend: savePreview() passes cropped as a PHP bool and false is the common case.

Fixes: #63229

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@solracsf solracsf added this to the Nextcloud 35 milestone Aug 15, 2026
@solracsf
solracsf requested a review from a team as a code owner August 15, 2026 06:16
@solracsf
solracsf requested review from CarlSchwan, icewind1991, provokateurin and salmart-dev and removed request for a team August 15, 2026 06:16
@solracsf

Copy link
Copy Markdown
Member Author

/backport to stable34

@solracsf

Copy link
Copy Markdown
Member Author

/backport to stable33

@solracsf solracsf self-assigned this Aug 15, 2026
@solracsf

Copy link
Copy Markdown
Member Author

Patch for 32bits failure: #63291

joinLocation() joins previews (p) with preview_locations (l) and
preview_versions (v). Both previews and preview_versions have a file_id
column, so any unqualified file_id condition is ambiguous and MySQL or
MariaDB reject the query with error 1052.

getPreviewForSpecification() built its conditions straight from the
caller's array keys, so this broke every preview save: savePreview() uses
that lookup to recover the existing row after a unique constraint
violation. getByFileId() had the same unqualified condition, while
getAvailablePreviewsForFile() next to it already used p.file_id.

Columns that come from the joined tables keep resolving to their own
alias, and keys that already carry one are passed through untouched.

The values are bound with an explicit type as well. An untyped false
binds as an empty string, which PostgreSQL rejects for a boolean column,
so qualifying the columns on their own only moved the error on that
backend.

Fixes: #63229

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf
solracsf force-pushed the fix/preview-mapper-query-correctness branch from 1a7f397 to 54bbb32 Compare August 15, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SQLSTATE 1052 "Column 'file_id' in WHERE is ambiguous" in PreviewMapper::getPreviewForSpecification on MySQL/MariaDB

1 participant