vittoriozamboni / django-groups-manager

Manage django groups collection based on django-mptt.
MIT License
100 stars 23 forks source link

Why is django-guardian required? #43

Closed BoPeng closed 4 years ago

BoPeng commented 4 years ago

From the documentation I had the feeling that guardian is optional, however, guardian is listed as a required package and will be installed with django-groups-manager,

https://github.com/vittoriozamboni/django-groups-manager/blob/729d76ca8dd8acd824e3eea22afbe7535a82d7fb/setup.py#L21

Then because guardian can be imported,

https://github.com/vittoriozamboni/django-groups-manager/blob/729d76ca8dd8acd824e3eea22afbe7535a82d7fb/groups_manager/perms.py#L4

django complains about

  File "manage.py", line 30, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib/python3.7/site-packages/groups_manager/models.py", line 22, in <module>
    from groups_manager.perms import assign_object_to_member, assign_object_to_group
  File "/usr/local/lib/python3.7/site-packages/groups_manager/perms.py", line 4, in <module>
    from guardian.shortcuts import assign_perm
  File "/usr/local/lib/python3.7/site-packages/guardian/shortcuts.py", line 27, in <module>
    GroupObjectPermission = get_group_obj_perms_model()
  File "/usr/local/lib/python3.7/site-packages/guardian/utils.py", line 228, in get_group_obj_perms_model
    from guardian.models import GroupObjectPermissionBase
  File "/usr/local/lib/python3.7/site-packages/guardian/models/__init__.py", line 1, in <module>
    from .models import (
  File "/usr/local/lib/python3.7/site-packages/guardian/models/models.py", line 69, in <module>
    class UserObjectPermission(UserObjectPermissionAbstract):
  File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 111, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class guardian.models.models.UserObjectPermission doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

So guardian has to be installed to INSTALLED_APPS. Should not django-guardian be removed from setup.py if it is indeed optional?

vittoriozamboni commented 4 years ago

You are right, I will amend this as soon as possible.