Skip to content

fix(ContentManager): look up existing row before insertOrUpdate - #262

Open
oboeglen wants to merge 1 commit into
nextcloud:mainfrom
oboeglen:fix/insertOrUpdate-missing-id
Open

fix(ContentManager): look up existing row before insertOrUpdate#262
oboeglen wants to merge 1 commit into
nextcloud:mainfrom
oboeglen:fix/insertOrUpdate-missing-id

Conversation

@oboeglen

Copy link
Copy Markdown

Fixes#261.

ContentManager::submitContent() always built a fresh QueueContentItem entity (no id) and called $this->mapper->insertOrUpdate($dbItem). QBMapper::insertOrUpdate() can only fall back to update() correctly when the entity's id is already known ahead of time — here it never is, so re-submitting content that was already indexed (unique constraint on app_id/provider_id/item_id) threw:

InvalidArgumentException: Entity which should be updated has no id

caught and logged by the existing catch (Exception $e), meaning the update silently never happened.

This PR looks up the existing row by its unique key first (new QueueContentItemMapper::findByUniqueKey()) and reuses its id when found, calling insert()/update() explicitly instead of relying on insertOrUpdate()'s exception-driven fallback with a freshly-constructed entity.

Reproduced with the bookmarks app re-crawling and re-submitting an already-indexed bookmark (full trace in #261), but the bug is generic to any provider re-submitting previously-indexed content.

@kyteinskykyteinsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix!
I had assumed it would auto-fallback on update when unique constrain fails but well it seems each db has its own way of doing that so your solution seems like the best approach here even with the two query calls instead of one.

Comment threadlib/Db/QueueContentItemMapper.php
@kyteinsky

Copy link
Copy Markdown
Contributor

A few other minor details:

insertOrUpdate() can only fall back to update() correctly when the
entity's id is already known ahead of time. submitContent() always
built a fresh QueueContentItem (no id), so re-submitting content that
was already indexed (unique constraint on app_id/provider_id/item_id)
threw InvalidArgumentException: Entity which should be updated has no
id, and the update silently never happened (caught and logged).
Look up the existing row by its unique key first and reuse its id
when present, calling insert()/update() explicitly instead of relying
on insertOrUpdate()'s exception-driven fallback.
Fixesnextcloud#261
Signed-off-by: Olivier <oboeglen@users.noreply.github.com>
@oboeglen
oboeglenforce-pushed the fix/insertOrUpdate-missing-id branch from a038031 to 5196d43CompareAugust 14, 2026 08:44
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

insertOrUpdate() throws "Entity which should be updated has no id" when re-submitting already-indexed content

2 participants

@oboeglen@kyteinsky