-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Add support for observing Many-to-Many field changes in ModelObserver #209
Open
tumblingman
wants to merge
13
commits into
NilCoalescing:master
Choose a base branch
from
tumblingman:m2m-changed-signal-handle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add support for observing Many-to-Many field changes in ModelObserver #209
tumblingman
wants to merge
13
commits into
NilCoalescing:master
from
tumblingman:m2m-changed-signal-handle
Conversation
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
…ges in some tests.
…d readability and flexibility
Ensure test consumers send JSON responses confirming subscription and unsubscription actions. Update tests to validate the new response payloads for improved accuracy and clarity. Fix timeout error on slow machines by explicitly waiting for subscription and unsubscription confirmation before proceeding with further test execution.
Integrated support for `m2m_changed` signals in `ModelObserver` to handle many-to-many relationship changes. Updated the `database_event` method accordingly and introduced a new test to validate m2m signal handling with actions such as add, remove, and clear operations. Adjusted test data to include `groups` field for verification.
Using `str(id(self))` for `dispatch_uid` ensures compatibility with cases where signal identifiers are expected to be strings. This change prevents potential issues in environments that enforce strict type checks.
Added a warning to highlight partial support for many-to-many fields in model observation. This warns about signal issues during object deletion and potential non-deterministic behavior due to Django's use of savepoints. References a long-standing Django bug for further context.
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces functionality for handling
m2m_changed
signals within theModelObserver
class, enabling observation of changes in many-to-many relationships.Note: This PR is dependent on #208 and must be reviewed and merged only after it. It is based on the commits from that PR.
Key Changes:
m2m_changed_receiver
) to handlem2m_changed
events for many-to-many fields._connect
method to dynamically registerm2m_changed
signals for all many-to-many fields in the observed model.post_add
,post_remove
, andpost_clear
actions.Additional Notes:
UnsupportedWarning
) to inform users about potential non-deterministic behavior when savepoints are used in transactions.ModelObserver
should be updated to reflect support for many-to-many field observation and its known limitations.This enhancement improves the versatility of the
ModelObserver
, allowing for more robust real-time updates in applications with many-to-many relationships.