Issues when using lifecycle with urlman (or in general with metaprogramming?)
Closed this issue · 3 comments
First of all.. Great job! This library simplifies a lot of stuff in my project :)
I am also depending on urlman that ultimately relies on some metaprogramming magic. Unfortunately when using it together with django-lifecycle I got a ValueError
. Consider this untested toy example:
from django_lifecycle import LifecycleModel, hook
import urlman
class Book(LifecycleModel):
author = models.ForeignKey('user.User')
class urls(urlman.Urls):
view = "/books/{self.pk}/"
@hook('after_update', when='author_id', has_changed=True)
def on_author_change(self):
do_thing()
Then when saving a Book
instance I got the error.
Traceback (most recent call last):
... omitted ...
self.instance.save()
File "/Users/andrea/venvs/foo/lib/python3.7/site-packages/django_lifecycle/__init__.py", line 157, in save
self._run_hooked_methods("before_update")
File "/Users/andrea/venvs/foo/lib/python3.7/site-packages/django_lifecycle/__init__.py", line 254, in _run_hooked_methods
for method in self._potentially_hooked_methods:
File "/Users/andrea/venvs/foo/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/andrea/venvs/foo/lib/python3.7/site-packages/django_lifecycle/__init__.py", line 241, in _potentially_hooked_methods
if hasattr(attr, "_hooked"):
File "/Users/andrea/venvs/foo/lib/python3.7/site-packages/urlman.py", line 63, in __getattr__
return self.get_url(attr)
File "/Users/andrea/venvs/foo/lib/python3.7/site-packages/urlman.py", line 71, in get_url
(attr, self.instance.__class__.__name__))
ValueError: No URL called '_hooked' on 'XXXXX'
The issue is solved by specifying _hooked
in the urls class but meh..
Please let me know if you think that this is a urlman related problem.
Interesting, thanks for raising this. I'll have to take a closer look at urlman, but yeah, definitely I want to minimize conflicts with other commonly used packages.
I ran into this too with urlman and came here to report it before seeing this issue.
This should be fixed now in latest release.