Org: Fixes event search index corrupted after fetch.#2495
Org: Fixes event search index corrupted after fetch.#2495cyrillkuettel wants to merge 2 commits into
Conversation
The fetch CLI switches schemas multiple times in a loop (remote → local per source key), violating the session_manager's own design contract: "we only set the schema once per request". Any ORM flush during the schema-switch window would send indexing signals tagged with the wrong schema. Wrap from_import() and the submit/publish/ticket block in disable_change_signals(), then explicitly index each added/updated published event after signals are restored.
Daverball
left a comment
There was a problem hiding this comment.
I think we can go a step further and directly emit the tasks to the indexer, instead of going the indirect route through the queue. You also forgot to handle the pruned events.
| if hasattr(app, 'fts_orm_events'): | ||
| for event_ in (*added, *updated): | ||
| if not event_.fts_skip: | ||
| app.fts_orm_events.index(local_schema, event_) |
There was a problem hiding this comment.
| if hasattr(app, 'fts_orm_events'): | |
| for event_ in (*added, *updated): | |
| if not event_.fts_skip: | |
| app.fts_orm_events.index(local_schema, event_) | |
| if app.fts_search_enabled: | |
| if added or updated: | |
| self.fts_indexer.process(( | |
| task | |
| for event_ in chained(added, updated) | |
| if ( | |
| task := self.fts_orm_events.index_task(local_schema, _event) # type: ignore[arg-type] | |
| ) is not None | |
| ), local_session) | |
| if purged: | |
| self.fts_indexer.process(( | |
| task | |
| for event_ in purged | |
| if ( | |
| task := self.fts_orm_events.delete_task(local_schema, _event) # type: ignore[arg-type] | |
| ) is not None | |
| ), local_session) | |
| # NOTE: Make sure all changes are flushed, before signals are emitted again | |
| local_session.flush() |
I think it's worth doing what we're doing in perform_reindex here and directly process the tasks using the indexer, instead of going through the queue, if you're already taking the extra step to manually emit the tasks.
You also forgot to emit delete tasks for the purged events.
There was a problem hiding this comment.
Ok this is updated now. The CI seems to be quite red, a lot of stuff failing on master as well. Seems unrelated tough.
There was a problem hiding this comment.
Redis 8 was just released, looks like that's the cause, pin it to <8 for now.
❌ 10 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
We have hourly cronjobs that fetch events. They look like this:
sudo /usr/sbin/container-exec onegov-cloud onegov-org --select /onegov_town6_without_yubikey/zug fetch --source huenenberg --source risch --source steinhausen --published-only --create-ticketsWe have empirically determined that this exact command above results in:

I have tested this fix (hotfix and run the cli manually) and with the fix this problem doesn't appear.
Commit message
Org: Fixes event search index corrupted after fetch.
The fetch CLI switches schemas multiple times in a loop (remote → local
per source key), violating the session_manager's own design contract:
"we only set the schema once per request". Any ORM flush during the
schema-switch window would send indexing signals tagged with the wrong
schema.
Wrap from_import() and the submit/publish/ticket block in
disable_change_signals(), then explicitly index each added/updated
published event after signals are restored.
TYPE: Bugfix
LINK: OGC-3101
Checklist