-
Notifications
You must be signed in to change notification settings - Fork 37
Fix motion history entry with deleted meeting #3222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
fa4733e
ca4c6e5
d0f7223
67e182e
c9f6898
d2c5215
487bfa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "_migration_index": 72, | ||
| "_migration_index": 73, | ||
| "gender":{ | ||
| "1":{ | ||
| "id": 1, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "_migration_index": 72, | ||
| "_migration_index": 73, | ||
| "gender":{ | ||
| "1":{ | ||
| "id": 1, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from datastore.migrations import BaseModelMigration | ||
| from datastore.writer.core.write_request import BaseRequestEvent, RequestUpdateEvent | ||
|
|
||
| from ...shared.filters import And, FilterOperator, Or | ||
|
|
||
|
|
||
| class Migration(BaseModelMigration): | ||
| """ | ||
| This migration removes mistakenly created history collection entries | ||
| """ | ||
|
|
||
| target_migration_index = 73 | ||
|
|
||
| def migrate_models(self) -> list[BaseRequestEvent] | None: | ||
| if self.reader.is_in_memory_migration: | ||
| return None | ||
| events: list[BaseRequestEvent] = [] | ||
| filter_ = And( | ||
| FilterOperator("original_model_id", "%=", "motion/%"), | ||
| FilterOperator("meeting_id", "!=", None), | ||
| FilterOperator("meta_deleted", "!=", True), | ||
| ) | ||
| potentially_broken_entries = self.reader.filter( | ||
| "history_entry", filter_, ["meeting_id"] | ||
| ) | ||
| potentially_affected_meetings = { | ||
| meeting_id | ||
| for entry in potentially_broken_entries.values() | ||
| if (meeting_id := entry.get("meeting_id")) | ||
| } | ||
| if potentially_broken_entries: | ||
| deleted_meetings = self.reader.filter( | ||
| "meeting", | ||
| And( | ||
| FilterOperator("meta_deleted", "=", True), | ||
| Or( | ||
| *[ | ||
| FilterOperator("id", "=", id_) | ||
| for id_ in potentially_affected_meetings | ||
| ] | ||
| ), | ||
| ), | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also just do a get_many on the meeting ids.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. That was something I was afraid of, too. I returned the commented out code instead and altered it a little. |
||
| events = [ | ||
| *[ | ||
| RequestUpdateEvent( | ||
| f"history_entry/{id_}", fields={"meeting_id": None} | ||
| ) | ||
| for id_, entry in potentially_broken_entries.items() | ||
| if entry["meeting_id"] in deleted_meetings | ||
| ], | ||
| ] | ||
| # meetings = self.reader.get_many( | ||
| # [ | ||
| # GetManyRequestPart("meeting", list(affected_meetings), ["meta_deleted"]) | ||
| # ] | ||
| # ).get("meeting", {}) | ||
| # events = [ | ||
| # *[ | ||
| # RequestUpdateEvent(f"history_entry/{id_}", fields={"meeting_id": None}) | ||
| # for id_, entry in potentially_broken_entries.items() | ||
| # if meetings[entry["meeting_id"]].get("meta_deleted") != True | ||
| # ], | ||
| # ] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using this now but taking advantage of the fact that no deleted meetings are returned. |
||
|
|
||
| return events | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really only for motions?
Why not just do it for all collections?
Shouldn't affect the rest of the code, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user history doesn't use the
meeting_idand the assignment isn't affected as shown by the alteration of that meeting delete test. Doing it though for extra security as this has just little affect on the request.