Skip to content

[Bug]: Column 'file_id' in WHERE is ambiguous in PreviewMapper::getByFileId() #63250

Closed as duplicate

Description

@shost

Bug description

After upgrading to Nextcloud 34.0.3 the command occ preview:pre-generate (from the Preview Generator app) fails with:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'file_id' in WHERE is ambiguous

Steps to reproduce

  1. Install / upgrade to Nextcloud 34.0.3
  2. Have the Preview Generator app (5.14.0) enabled
  3. Run:
    sudo -u www-data php occ preview:pre-generate
  4. The command crashes with the ambiguous column error.

Cause

In lib/private/Preview/Db/PreviewMapper.php the method getByFileId() still uses an unqualified column name:

public function getByFileId(int $fileId): \Generator {
    $selectQb = $this->db->getQueryBuilder();
    $this->joinLocation($selectQb)
        ->where($selectQb->expr()->eq('file_id', $selectQb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
    yield from $this->yieldEntities($selectQb);
}

joinLocation() performs a LEFT JOIN on preview_versions (alias v), which also contains a file_id column.
The other methods in the same class (getAvailablePreviewsForFile, getAvailablePreviews) correctly use the alias p.file_id.

Fix

Change the line to:

->where($selectQb->expr()->eq('p.file_id', $selectQb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));

Server configuration

Nextcloud version: 34.0.3
Preview Generator app: 5.14.0
PHP: 8.4.24
Database: MySQL

Additional notes

This is a regression introduced with the new oc_previews / oc_preview_versions tables.

Activity

  1. amessina commented on Aug 14, 2026

    @amessina

    Same result with PostgreSQL.
    Also related #63229.

  2. joshtrichards commented on Aug 14, 2026

    @joshtrichards
    Member

    Agreed. Covered as the second matter in #63229 so I'll close as a duplicate. Feel free to send in a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions