DEFAULT Django Session is still using File in /tmp (Can't read from directory)

200 views
Skip to first unread message

Andre Foote

unread,
Apr 27, 2021, 9:04:33 AM4/27/21
to Django users
I've wired up a Django 3.0.1 Application using the default, DB-backed session configurations.

MIDDLEWARE has "django.contrib.sessions.middleware.SessionMiddleware",
INSTALLED_APPS has "django.contrib.sessions".

During file import (using django-import-export) I see that while session records are appearing in a database (SQL Server) table (dbo.django_session).

However, the application crashes with the error stating that it is unable to read the session data stored in "/tmp". These session files are saved with permissions "rw-------".

I've tried the following commands to enforce file readability from this directory:

    umask 002
    chmod g+s /tmp
    setfacl -d -m u::rw,g::rw,o::rw /tmp

but some process (either django, or the web server) keeps writing to the folder as "rw-------", after which the app crashes because it cannot read the file.

The primary issue I bring up is that despite DEFAULT session configuration (DB-backed sessions), Django is still referring to files.

My secondary issue is a question to anyone about how to ensure that session data being written to /tmp can be read.

Ryan Nowakowski

unread,
Apr 27, 2021, 3:52:03 PM4/27/21
to django...@googlegroups.com


On April 26, 2021 11:31:24 PM CDT, Andre Foote <andref...@gmail.com> wrote:
>However, the application crashes with the error stating that it is
>unable
>to read the session data stored in "/tmp".

Please post the full error including any exception messages and the full Python trace back if available.

Andre Foote

unread,
Apr 28, 2021, 12:15:57 AM4/28/21
to Django users
FileNotFoundError at /admin/region/country/process_import/
[Errno 2] No such file or directory: '/tmp/tmpu31qxebf'
Request Method: POST
Django Version: 3.0.10
Exception Type: FileNotFoundError
Exception Value:
[Errno 2] No such file or directory: '/tmp/tmpu31qxebf'
Exception Location: /usr/local/lib/python3.8/site-packages/import_export/tmp_storages.py in open, line 29
Python Executable: /usr/local/bin/python
Python Version: 3.8.3

I understand from the Django docs that when using File-based sessions, one must check that their "web server has permissions to read and write to this location" (I'm not sure how/where to enforce this, in my initial post, I tried to enforce inheritence of folder permissions but that didn't work - any pointers would be appreciated.)

However I'm using the default configuration for sessions that's supposed to be database-backed.

Ryan Nowakowski

unread,
Apr 28, 2021, 7:41:24 AM4/28/21
to django...@googlegroups.com
What makes you think this has anything to do with Django sessions?

Andre Foote

unread,
Jun 9, 2021, 2:26:38 AM6/9/21
to Django users
Because this is all coming from when I enabled sessions and the server admin tried to implement the application on multiple nodes.

Ryan Nowakowski

unread,
Jun 13, 2021, 6:02:26 PM6/13/21
to Django users
You probably don't want to use file-based sessions if you're load
balancing your application across multiple nodes. If your session gets
created on one application node, how will the other application nodes
have access to it? This might work if you have access to each
file-based session on every node via NFS or something like it. Rather
than do that, I'd recommend storing your sessions in the database or
some other service like redis.

On Tue, Jun 08, 2021 at 11:26:38PM -0700, Andre Foote wrote:
> Because this is all coming from when I enabled sessions and the server
> admin tried to implement the application on multiple nodes.
>
> On Wednesday, April 28, 2021 at 6:41:24 PM UTC+7 Ryan Nowakowski wrote:
>
> > What makes you think this has anything to do with Django sessions?
> >
> >
> > On April 27, 2021 11:15:57 PM CDT, Andre Foote <andref...@gmail.com>
> > wrote:
> >>
> >> FileNotFoundError at /admin/region/country/process_import/
> >> [Errno 2] No such file or directory: '/tmp/tmpu31qxebf'
> >> *Request Method*: POST
> >> *Request URL*: http://myurl/admin/region/country/process_import/
> >> *Django Version*: 3.0.10
> >> *Exception Type*: FileNotFoundError
> >> *Exception Value*:
> >> [Errno 2] No such file or directory: '/tmp/tmpu31qxebf'
> >> *Exception Location*: /usr/local/lib/python3.8/site-packages/import_export/tmp_storages.py
> >> in open, line 29
> >> *Python Executable*: /usr/local/bin/python
> >> *Python Version*: 3.8.3
> >>
> >> I understand from the Django docs
> >> <https://docs.djangoproject.com/en/3.2/topics/http/sessions/#using-file-based-sessions> that
> >> when using File-based sessions, one must check that their "web server has
> >> permissions to read and write to this location" (I'm not sure how/where to
> >> enforce this, in my initial post, I tried to enforce inheritence of folder
> >> permissions but that didn't work - any pointers would be appreciated.)
> >>
> >> However I'm using the default configuration for sessions that's supposed
> >> to be database-backed.
> >> On Tuesday, April 27, 2021 at 9:52:03 PM UTC+2 Ryan Nowakowski wrote:
> >>
> >>>
> >>>
> >>> On April 26, 2021 11:31:24 PM CDT, Andre Foote <andref...@gmail.com>
> >>> wrote:
> >>> >However, the application crashes with the error stating that it is
> >>> >unable
> >>> >to read the session data stored in "/tmp".
> >>>
> >>> Please post the full error including any exception messages and the full
> >>> Python trace back if available.
> >>>
> >>
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4bcccbc-17b9-4507-9b17-7c477f0193aan%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages