I've been developing a Django 1.0 project (using Pinax, actaully) on a
machine that has PostgreSQL 8.1.11 (Linux), where things work just
fine.  Now I've deployed to a (still development) customer visible
server that has an 8.4 PostgreSQL (also on Linux), which throws errors
complaining that equals doesn't know how to compare a character
varying with an integer.

Not much analysis reveals that that folks are accustomed to treating
the FriendInvitation.status field, a models.CharField with
max_length=1 and a set of choices whose DB side representation is a
string composed of a single decimal digit, with literal ints (e.g.;
self.status = 5 in the FriendInvitation.accept()).  This is
django_friends version 0.1.2.  I'm hitting the problem on a queryset
with exclude(status=8).

Some testing with psql shows that of:

  select * from friends_friendshipinvitation where status = '8' ;

and

  select * from friends_friendshipinvitation where status = 8 ;

work fine on pg8.1.11, but only the first works on pg8.4 (the column
is character varying(1) in both databases).

My presumption is that the older PostgreSQL, expecting to have to
decide whether unquoted things are strings (e.g.; "status" in the
query samples above), used to look at the context and decided that we
had meant the 8 as a string.  That probably led to difficult to
diagnose errors, and they have tightend up in 8.4.  I can still get
away with not quoting the table and field names (so long as they don't
have funny characters), but things that look like numbers now are
numbers unless quoted.

I can make myself a copy of django_friends that won't get updated when
Pinax does, and patch it to work, but since I found my failure in a
profiles app that uses friends, I wonder how many other places I'll
have to patch.

It occurs to me that the ORM could fix this.  It knows that status is
a CharField.  For anything but None (which it should try to store as
null) it should be reasonable to apply str() (or unicode()) to the
field value before storing it.  str(8) -> '8' (and unicode(8) ->
u'8'), while str() applied to a string (or unicode() applied to a
unicode string) leaves it unchanged (doesn't even copy in, in a few
quick tests in python 2.6.2).  Then the backend will know to quote it.

Thoughts?  Workaround suggestions?

Bill

--~--~---------~--~----~------------~-------~--~----~
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