-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and enhance many-to-many change handling in ModelObserver
Added checks for `through` attribute and improved handling of `pre_clear` and `reverse` cases in many-to-many field changes. Enhanced the logic to avoid duplicates and ensure correct updates to related instances. Updated tests to validate these changes, ensuring robust many-to-many relationship observation.
- Loading branch information
1 parent
ba2f2d2
commit 79b0897
Showing
2 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import asyncio | ||
from contextlib import AsyncExitStack | ||
|
||
import pytest | ||
|
@@ -685,3 +684,54 @@ async def accept(self, subprotocol=None): | |
await database_sync_to_async(u2.groups.set)([g1, g4]) | ||
|
||
await communicator.receive_nothing() | ||
|
||
await database_sync_to_async(u1.groups.set)([g1, g2, g3, g4]) | ||
|
||
response = await communicator.receive_json_from() | ||
|
||
assert response == { | ||
"action": "update", | ||
"errors": [], | ||
"response_status": 200, | ||
"request_id": 4, | ||
"data": { | ||
"email": "[email protected]", | ||
"id": u1.id, | ||
"username": "test1", | ||
"groups": [g1.id, g2.id, g3.id, g4.id] | ||
}, | ||
} | ||
|
||
await database_sync_to_async(g4.user_set.clear)() | ||
|
||
response = await communicator.receive_json_from() | ||
|
||
assert response == { | ||
"action": "update", | ||
"errors": [], | ||
"response_status": 200, | ||
"request_id": 4, | ||
"data": { | ||
"email": "[email protected]", | ||
"id": u1.id, | ||
"username": "test1", | ||
"groups": [g1.id, g2.id, g3.id] | ||
}, | ||
} | ||
|
||
await database_sync_to_async(g3.user_set.remove)(u1) | ||
|
||
response = await communicator.receive_json_from() | ||
|
||
assert response == { | ||
"action": "update", | ||
"errors": [], | ||
"response_status": 200, | ||
"request_id": 4, | ||
"data": { | ||
"email": "[email protected]", | ||
"id": u1.id, | ||
"username": "test1", | ||
"groups": [g1.id, g2.id] | ||
}, | ||
} |