Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#29005 closed New feature (wontfix)

django object builder

Reported by: Sergey Glazyrin Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords: builder 3party
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello guys!

I faced a situation where I need to patch django.contrib,auth.get_user function because the "openstack auth backend" should be aware of django request.
Let me describe the situation.

We use django-websocket-redis python package for websocket stuff. We do subscribe to user's channels, so, uwsgi_websocket process should be aware of currently signed in user.

For example, here, django websocket redis requires a recognized user in request object
https://github.com/jrief/django-websocket-redis/blob/master/ws4redis/redis_store.py#L22

BUT, the backend we use in our project requires "request object" inside to recognize if user signed in.

https://github.com/openstack/horizon/blob/master/openstack_auth/backend.py#L78

And as it suggests, it requires some monkey-patching

This required monkey-patching the contrib.auth middleware
to make the request object available to the auth backend class.

Instead I propose to add a simple way to do monkey patching directly in django

For such purpose I added simple changes based on "Builder" design pattern, so we may build Django object in iterative way and avoid monkey patches at all in different python packages.

https://github.com/django/django/compare/master...sergeyglazyrindev:master

Such change will simplify django object adaptation in another python packages.

What do you think ?

Change History (2)

comment:1 by Tim Graham, 7 years ago

Resolution: wontfix
Status: newclosed

Isn't the root problem fixed by 4b9330ccc04575f9e5126529ec355a450d12e77c, Fixed #25187 -- Made request available in authentication backends ?

Maybe I don't understand the usefulness, but DjangoObjectBuilder looks complicated and out of place in Django. Usually we prefer to fix problems and add more understandable extensions points rather than ease monkey patching.

comment:2 by Sergey Glazyrin, 7 years ago

I need request object in get_user function. Besides of its available in authenticate method, but it would be useful to have it in auth backend object as attribute of this object. So all methods of the backend get access to request.

https://github.com/openstack/horizon/blob/master/openstack_auth/backend.py#L78

Well, about djangoobjectbuilder, it simplifies patching Django objects in any place you want and it's totally up to Martin Fowler catalog of design patterns.
Right now to achieve what I need, I redefine function get_user from django.contrib.auth module and this is bad idea because then I'll need to keep it up when update Django, etc, but with my solution, we change almost nothing.

Note: See TracTickets for help on using tickets.
Back to Top