Fix motion history entry with deleted meeting#3222
Conversation
| deleted_meetings = self.reader.filter( | ||
| "meeting", | ||
| And( | ||
| FilterOperator("meta_deleted", "=", True), | ||
| Or( | ||
| *[ | ||
| FilterOperator("id", "=", id_) | ||
| for id_ in potentially_affected_meetings | ||
| ] | ||
| ), | ||
| ), | ||
| ) |
There was a problem hiding this comment.
You could also just do a get_many on the meeting ids.
Deleted meetings will be filtered out and you won't potentially have a filter with 100s of lines of conditions.
Like this I am afraid the datastore request may break with too large of an instance.
There was a problem hiding this comment.
Yes. That was something I was afraid of, too. I returned the commented out code instead and altered it a little.
| return None | ||
| events: list[BaseRequestEvent] = [] | ||
| filter_ = And( | ||
| FilterOperator("original_model_id", "%=", "motion/%"), |
There was a problem hiding this comment.
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.
The user history doesn't use the meeting_id and 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.
| # 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 | ||
| # ], | ||
| # ] |
There was a problem hiding this comment.
Using this now but taking advantage of the fact that no deleted meetings are returned.
When deleting a meeting that meeting will delete its motions which will then create new history entries after the relation handling. That needs to be accounted for when creating entries that are referring to be deleted meetings.