Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7686487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:29:32+00:00 2026-05-31T19:29:32+00:00

Updated question: Django is giving me the following sql query: SELECT auth_user.id, auth_user.username, auth_user.first_name,

  • 0

Updated question:

Django is giving me the following sql query:

SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."username" = %s  args=('andrew',);

If I execute the sql query in the postgresql command line, I get the following error:

ERROR:  syntax error at or near "%"
LINE 1: ..." FROM "auth_user" WHERE "auth_user"."username" = %s  args=(...
                                                             ^

However, when I slightly modify the statement, then I get the cirrect result from postgresql.

SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."username" = 'andrew';

Is the Django generated query incorrect?


Hi Stackoverflow people,

Very simple code which drives me crazy:

I want to extract the user information from user_auth with

user = get_object_or_404(User, pk = request.user.pk)

However, I get an error message in Django:

'NoneType' object does not support item assignment

When I check the sql query and execute it in the psql command line, psql gives me also an error message, which makes me thinking that the statement might be incorrect.

psql statement is:

SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = %s ; args=(7,)

Why does it say %s in the WHERE statement? The user id is not a string.

I believe the solution must be very simple – but I can figure out what the issue is here.
Thank you for your help and suggestions!

Additional explanation

I am using the django_social_auth package for the user authentification. The user will be directed to the dashboard site once the 3rd part cleared the credentials, therefore I would assume that request.user is not None.

Complete traceback

Environment:


Request Method: GET
Request URL: http://login.test.com:8000/profile/dashboard/

Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.gis',
 'django.contrib.messages',
 'django.contrib.markup',
 'django.contrib.staticfiles',
 'django.contrib.flatpages',
 'django.contrib.humanize',
 'guardian',
 'easy_thumbnails',
 'userena',
 'userena.contrib.umessages',
 'south',
 'django_extensions',
 'debug_toolbar',
 'social_auth',
 'djangoratings',
 'about',
 'apps.profiles',
 'apps.map',
 'apps.contact',
 ]
Installed Middleware:
['django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware']


Traceback:
File "/Users/neurix/Development/test/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/neurix/Development/test/test/apps/profiles/views.py" in dashboard
  35.     extra_context['username'] = user.username

Exception Type: TypeError at /profile/dashboard/
Exception Value: 'NoneType' object does not support item assignment

views.py

...
31: print "user: %s" %(request.user.pk)
32: user = get_object_or_404(User, pk = request.user.pk)
33:
34: 
35: extra_context['username'] = user.username
36: if user.first_name:
37:     extra_context['name'] = user.first_name
...

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:29:33+00:00Added an answer on May 31, 2026 at 7:29 pm

    Could it be that request.user is None?

    if request.user is not None:
        user = get_object_or_404(User, pk = request.user.pk)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Updated question given Andrew Hare's correct answer: Given the following C# classes: public class
Here is the updated question: the current query is doing something like: $sql1 =
UPDATED QUESTION Since the ctor is not supported by .NETCF (public FileStream(IntPtr handle, FileAccess
Updated question, see below I'm starting a new project and I would like to
UPDATED QUESTION: Ok, I am going to simplify my question since I don't really
ORIGINAL (see UPDATED QUESTION below) I am designing a new laboratory database that tests
Question Updated for Bounty In Flash I need to load a dynamically generated XML
UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom
N.B THIS QUESTION HAS BEEN UPDATED, READ FURTHER DOWN Hi, I want to create
Updated Appears to be a precedence error and nothing to do with the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.