User model not using persistent DB connection?

25 views
Skip to first unread message

Bobby Mozumder

unread,
Dec 29, 2016, 4:14:41 PM12/29/16
to Django users
Hi,

It seems Django doesn’t use a persistent DB connection whenever I use the Request.User object.

I always get a signal saying a new DB connection occurs when I call the object.

For example:

class MyView(DetailView):
    def get(self, request, slug):
        print(request.user) # <--- Boom, new database connection signal is sent here.
        # continue processing view
pass

Is that by design?  Or is it an error?  

I’d like it to use the same persistent DB connection across all requests. 

I’m looking through the Django source (auth & sessions backend) and can’t find where the DB connection is happening.  I haven’t touched the User models at all, although I do have a DB connection receiver that runs prepared statements when the app starts - it’s where I found this.  

Any info on this is appreciated, & happy Holidays!

-bobby

James Bennett

unread,
Dec 29, 2016, 4:17:31 PM12/29/16
to django...@googlegroups.com
See the documentation for details:


Also, generally speaking maintaining a connection pool has been seen as out of scope for Django itself, and most people use a standalone connection pooler (such as pgpool for Postgres).

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/A56E8EB4-EE0A-477F-B8DD-F39AA43F71EB%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Bobby Mozumder

unread,
Dec 29, 2016, 6:02:47 PM12/29/16
to django...@googlegroups.com
I’m actually already setting CONN_MAX_AGE to None on a connection pool.  The rest of the queries in the view are using the persistent connection pools.

It’s only this specific request.user object that keeps creating a new connection instead of using the persistent connection for some reason.

-bobby

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages