pakal / django-compat-patcher

A system to improve compatibility between different Django versions, and make upgrading dependencies less painful.
MIT License
13 stars 2 forks source link

user.is_authenticated #11

Closed jayvdb closed 4 years ago

jayvdb commented 4 years ago

It became a property circa 1.9/1.10

  File "/usr/lib/python3.8/site-packages/experiments/utils.py", line 46, in _get_participant
    elif user and user.is_authenticated():
TypeError: 'bool' object is not callable
jayvdb commented 4 years ago

Where it changes in Django https://github.com/django/django/commit/c1aec0feda7

I hit this one quite often; e.g. https://github.com/willandskill/django-executor/pull/1#discussion_r429519195 https://github.com/andrewyoung1991/django-restframework-stripe/pull/2#discussion_r425979305

pakal commented 4 years ago

Hm indeed, I had skip this one as "particularly hard", but now that I think about it, maybe returning a custom class instance, with proper bool and call methods, would do it?

But then comparisons with other values must be handled too...

I have to think a bit more, surely there will be a need for subclassing builtin type "bool" - https://jfine-python-classes.readthedocs.io/en/latest/subclass-int.html

It looks doable, although I know from numerous people who tried, that it's always a hazardous path ^^

jayvdb commented 4 years ago

https://github.com/clarete/forbiddenfruit is getting quite good.

jayvdb commented 4 years ago

https://github.com/aalekseev/healthy-projects/tree/master/src/django_patches/user_is_authenticated (code patcher, it seems)

pakal commented 4 years ago

OK I've added a fixer for this, restauring their old "CallableBool" class - it's all in master branch. Please let me know if related problems are not solved by this.

I don't know why it doesn't just work by subclassing "int", but I'd better stay close to the original shim implementation B-) ForbiddenFruit and the likes seem powerful, but it's safer to stay compatible with all Python implementations I guess.