Hi guys! New poster here and django newbie, though I'm starting to get
a handle on it now.

One issue though which is preventing release of my project is a truely
bizarre bug pertaining *purely* to postgres. I'm running Django
(1.3.1) with psycopg2 (2.2.1) and despite everything working on the
development 'runserver' server using SQLite, at some point during this
project the 'production' server running on mod_python no longer works.

The fault specifically pertains to a custom authentication module
which gets XML data over an HTTP call with pycurl. When logged in as a
regular 'ModelBackend' user, everything works fine. However when
trying to create a new User object as such:

...
except User.DoesNotExist:
    # Create a new user. Note that setting the password really doesn't
mean anything.
        user = User(
            username=username,
            email=username,
            password='',
            first_name=user_firstname,
            last_name=user_lastname
        )
>>>>user.save()
...

...I get the following Exception when calling save():

Exception Type: DatabaseError
Exception Value: can't adapt type 'NavigableString'
(traceback: http://dpaste.com/704253/)

The local variables at the time of exception are:

username:       u'matt...@example.com'
c: <pycurl.Curl object at 0x7fd619833430>
password: u'xxxxxxxxxxxxx'
user_firstname: u'Matthew'
user_lastname: u'Cotterell'
self: <portal.auth.backends.EntropyBackend object at 0x7fd619793290>
storage: <StringIO.StringIO instance at 0x7fd61977fcf8>
user: <User: matt...@example.com>
url_string: 'https://auth.example.com:8181/ExternalAuthentication/
Login?username=matt...@example.com&password=xxxxxxxxxxxxx'

And seem to have been caused by psycopg2 here:

/usr/local/lib/python2.6/dist-packages/django/db/backends/
postgresql_psycopg2/base.py in execute

    """
    def __init__(self, cursor):
        self.cursor = cursor
    def execute(self, query, args=None):
        try:
>>>>       return self.cursor.execute(query, args) ...
        except Database.IntegrityError, e:
            raise utils.IntegrityError,
utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
        except Database.DatabaseError, e:
            raise utils.DatabaseError, utils.DatabaseError(*tuple(e)),
sys.exc_info()[2]
    def executemany(self, query, args):

query: 'INSERT INTO "auth_user" ("username", "first_name",
"last_name", "email", "password", "is_staff", "is_active",
"is_superuser", "last_login", "date_joined") VALUES (%s, %s, %s, %s,
%s, %s, %s, %s, %s, %s)'
self: <django.db.backends.postgresql_psycopg2.base.CursorWrapper
object at 0x7fd6198806d0>
args: (u'matt...@example.com',
 u'Matthew',
 u'Cotterell',
 u'matt...@example.com',
 u' ',
 False,
 True,
 False,
 u'2012-02-17 15:34:59.735209',
 u'2012-02-17 15:34:59.735222')
e: ProgrammingError("can't adapt type 'NavigableString'",)

So I know everything on my end is at least getting filled in properly.
Oddly enough, if I comment out the first_name and last_name lines, it
goes through (and causes a similar exception a few lines ahead on a
similar 'object creation' section of code. So maybe it's somethign to
do with those two lines?

It's just bizzare, I'm creating objects for other areas of the
projects perfectly fine, it's just here that it's being stubborn.
Googling the issue only highlights the fact it's likely a psycopg2
issue, but not much else.

Thanks so much to anyone who can help me here, I'm completely stumped
as to why such a simple operation can go so wrong...

Matt

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to