Search code examples
djangoprocessuwsgi

Django keeps reporting the same error after I already edited views.py


I am editing a Django 2.2 application and I received an Exception:

TypeError at /myappname/myurl
'RelatedManager' object is not iterable
Exception Location: /myprojectlocation/myappname/views.py in myview, line 41

Whoops, I accidentally typed .objects instead of .objects.all(). Easy fix.

But now, no matter how I edit views.py, I keep receiving the exact same exception, always pointing at line 41. I even commented line 41 out entirely, and still get the same exception. The exception Traceback shows the updated line 41, so I know I am definitely editing the right file and the changes are being saved, but the actual exception itself just keeps complaining about that RelatedManager no matter what I edit.

I've restarted the webserver and I've cleared all my browsing data. So what on earth is still "remembering" the old code that I've edited many times since?


Update: Everything is fine on the django development server (manage.py runserver). So apparently it's more of a uWSGI/nginx problem than anything I'm doing wrong with my django files.


Solution

  • Turns out that somehow my tmp/uwsgi.pid file wound up with the wrong process ID in its contents, so I was unwittingly failing to stop the master uWSGI process when I thought I was restarting the Django application.

    I used pstree -p to see my process hierarchy and get the correct process ID of the master uWSGI process, edited uwsgi.pid to contain that correct ID, used pkill -9 -f \path\to\my\application to kill the process, and finally restarted my application again.