jazzband / django-waffle

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

Custom WAFFLE_FLAG_MODEL not working after 0.15 #380

Open aleehedl opened 4 years ago

aleehedl commented 4 years ago

I have added a custom waffle flag which inherits from the AbstractBaseFlag and doesn't have a users field. After upgrading waffle to a newer version I get the following error during startup:

Traceback (most recent call last):
  File "manage.py", line 30, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.8/site-packages/django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/usr/local/lib/python3.8/site-packages/waffle/apps.py", line 9, in ready
    import waffle.signals  # noqa: F401
  File "/usr/local/lib/python3.8/site-packages/waffle/signals.py", line 7, in <module>
    @receiver(m2m_changed, sender=get_waffle_flag_model().users.through)
AttributeError: type object 'Flag' has no attribute 'users'

The docs say that the Flag needs to be a subclass of AbstractBaseFlag yet the signal receiver is accessing the users field which is only found in AbstractUserFlag. I'm guessing this is the breaking commit: afb2660449d. How should I go about this problem?

aleehedl commented 4 years ago

My current workaround to get the app running:

class Flag(AbstractBaseFlag):
    class MockM2MRelation:
        through = None

    users = MockM2MRelation()
    groups = MockM2MRelation()
    # ...