jazzband / django-waffle

A feature flipper for Django
https://waffle.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.12k stars 257 forks source link

AttributeError attempting to flush m2m cache #377

Open sirdodger opened 4 years ago

sirdodger commented 4 years ago

I am running a Django 2.2.11 (but I also tested with 2.2.15) installation with django-waffle 1.0.0, and I am getting a failure in the m2m signal. As far as I can tell from the docs, that should be allowed?

File "/usr/local/lib/python3.5/dist-packages/waffle/signals.py", line 11, in flag_membership_changed
    instance.flush()
AttributeError: 'User' object has no attribute 'flush'

I can replicate it with a clean installation.

k4rl85 commented 3 years ago

I bumped on the same issue. After some digging i found a problem in the signal receiver flag_membership_changed.

This issue is caused by how m2m_changed retrieve the instance. The code except to receive always an instance of model Flag but this is not guarantee from m2m_changed signal.

More info here https://docs.djangoproject.com/en/dev/ref/signals/#m2m-changed