Skip to content
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

Enable diffing m2m fields #932

Merged
merged 6 commits into from Sep 28, 2022
Merged

Enable diffing m2m fields #932

merged 6 commits into from Sep 28, 2022

Conversation

thijskramer
Copy link
Contributor

At first @avalanchy did the initial work. After that https://github.com/bmedx made an excellent PR based on his work which wasn't completed, so I tried to make it work and created a PR myself, based on edx#1 and rebased on the current master.

Description

This PR enables tracking history of m2m relations. It works in my specific situation, however I would be happy to hear if there are any situations I haven't looked at, I should cover or simply could be improved.

Related Issue

#399 - Track history of M2M fields

Motivation and Context

A few days ago I received the question "how can I see who has removed an article from this category?" I immediately dove into the history I had enabled, but I quickly discovered that m2m relations weren't tracked. I started googling for solutions and stumbled upon the Pull Request @bmedx made for #399.
I installed his fork and after some minor tweaks and a rebase, I made it work for my situation.
It tracks each m2m change in a separate m2m_history model, so that you won't need a reference to the actual referenced model.

How Has This Been Tested?

Tests have been included, however I'm unsure if they are enough to cover all use cases.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run the pre-commit run command to format and lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

simple_history/models.py Outdated Show resolved Hide resolved
@jeking3
Copy link
Contributor

jeking3 commented Feb 4, 2022

I wonder if perhaps the PR title is not quite right, since this seems to be doing more than allowing for a diff.

@lazarust lazarust mentioned this pull request Mar 16, 2022
@lazarust
Copy link

@thijskramer It looks like some tests failed in the GH Action, could you look into that? This feature would be really helpful for me!

@thijskramer
Copy link
Contributor Author

thijskramer commented Mar 17, 2022 via email

@utapyngo
Copy link
Member

@lazarust can you work this around by converting your m2m relation into an explicit model and adding history to it?
I really want #866 to be released ASAP, and this PR has conflicts and broken tests.

@thijskramer thijskramer force-pushed the m2m-support branch 2 times, most recently from c3444e8 to 4b7538d Compare March 23, 2022 07:32
lazarust
lazarust previously approved these changes Mar 25, 2022
Copy link

@lazarust lazarust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked through this and it looks good to me! Hopefully it can get merged in soon!!

@thijskramer
Copy link
Contributor Author

thijskramer commented Mar 25, 2022 via email

ddabble added a commit to MAKENTNU/web that referenced this pull request Apr 6, 2022
`django-simple-history` doesn't currently track changes to many-to-many relationships - which was the main point of this commit
(i.e. to track the changes to `own_permissions`) - but once jazzband/django-simple-history#399 is resolved
(likely through jazzband/django-simple-history#932), it will.
@legau
Copy link
Contributor

legau commented Jun 14, 2022

I fixed your tests on thijskramer#20
This should be good once merged into your branch

@legau
Copy link
Contributor

legau commented Jun 14, 2022

One more to go thijskramer#21 to resolve conflicts with master

@thijskramer
Copy link
Contributor Author

I think it's cleaner to rebase this branch onto master, isn't it?

bmedx and others added 5 commits June 14, 2022 14:13
Working prototype with tests

- Custom through models may not work correctly
- Currently storing IDs for FKs, probably needs replacing

Now using model instances instead of IDs when possible

flake8 fixes

Delete dead code, comments, and change to bulk create

Clean up, add m2m support to diff_against

Add basic tests for several m2m fields on one model

Formatting fixes from Black

Housekeeping, fixing Python 2.7, removing Python 3.4

- Py3.4 removed as coverage no longer supports it, could be pinned instead, but I went with this.

remove python2 thing
@legau
Copy link
Contributor

legau commented Jun 14, 2022

Indeed I tried that but with my own branch so it conflicts with your branch now

@thijskramer
Copy link
Contributor Author

Indeed I tried that but with my own branch so it conflicts with your branch now

I've rebased my branch!

@legau
Copy link
Contributor

legau commented Jun 15, 2022

I added inheritance support with thijskramer#22

@ipeterov
Copy link

Sorry about a comment that isn't immediately relevant, I just wanted to say that I really want the feature and I'm very happy to see the current activity.

Thank you @thijskramer and @legau for your work!

@cpackard
Copy link

hey all, any reason this couldn't be merged? m2m field tracking would be a huge plus!

@codecov
Copy link

codecov bot commented Sep 27, 2022

Codecov Report

Merging #932 (603c7e3) into master (529dbe2) will decrease coverage by 0.53%.
The diff coverage is 87.87%.

@@            Coverage Diff             @@
##           master     #932      +/-   ##
==========================================
- Coverage   97.65%   97.11%   -0.54%     
==========================================
  Files          23       23              
  Lines        1149     1215      +66     
  Branches      222      237      +15     
==========================================
+ Hits         1122     1180      +58     
- Misses         12       17       +5     
- Partials       15       18       +3     
Impacted Files Coverage Δ
simple_history/models.py 96.38% <87.87%> (-1.39%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@valberg valberg merged commit 7042a64 into jazzband:master Sep 28, 2022
@legau legau mentioned this pull request Sep 28, 2022
11 tasks
@cpackard
Copy link

@thijskramer @valberg @legau @johanneswilm thanks for all the work and merging this in 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants