Skip to content

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

Merged
kyteinsky merged 2 commits into
nextcloud:mainfrom
oboeglen:fix/insertOrUpdate-missing-id
Aug 28, 2026
Merged

fix(ContentManager): look up existing row before insertOrUpdate#262
kyteinsky merged 2 commits into
nextcloud:mainfrom
oboeglen:fix/insertOrUpdate-missing-id

Conversation

@oboeglen

@oboeglen oboeglen commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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.

@kyteinsky kyteinsky 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 thread lib/Db/QueueContentItemMapper.php Outdated
@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.

Fixes nextcloud#261

Signed-off-by: Olivier <oboeglen@users.noreply.github.com>
@oboeglen
oboeglen force-pushed the fix/insertOrUpdate-missing-id branch from a038031 to 5196d43 Compare August 14, 2026 08:44
@github-actions

Copy link
Copy Markdown

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Signed-off-by: kyteinsky <kyteinsky@gmail.com>
Assisted-by: Github Copilot:claude-opus-5
@kyteinsky
kyteinsky force-pushed the fix/insertOrUpdate-missing-id branch from d674b5b to 27a789c Compare August 28, 2026 00:36
@kyteinsky kyteinsky added the AI assisted This PR contains AI-assisted commits label Aug 28, 2026
@kyteinsky
kyteinsky merged commit 59d1ae9 into nextcloud:main Aug 28, 2026
20 of 29 checks passed
@kyteinsky

Copy link
Copy Markdown
Contributor

thanks again, I fixed the DB query to only fetch the id column.

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

Labels

AI assisted This PR contains AI-assisted commits feedback-requested

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