On Apr 13, 7:25 pm, gordyt <gor...@gmail.com> wrote:
> Howdy Folks,
>
> I have been testing model inheritance using models that have UUIDField
> primary keys.  It appears that when you save a new instance of a child
> model, the framework is not calling get_db_prep_value() to convert the
> UUIDField to a proper format before querying the parent entry.
>
> Let's say we have two very simple models:
>
> class Person(models.Model):
>     id = UUIDField(primary_key=True)
>     name = models.CharField(max_length=32)
>
> class Child(Person):
>     grade = models.SmallIntegerField()
>
> If you do this...
>
> c = Child(name="Mary", grade=5)
> c.save()
>
> ...the framework will first create the myapp_person entry.  Then it
> does a query like this:
>
> SELECT (1) AS "a" FROM "myapp_child" WHERE
> "myapp_child"."person_ptr_id" = %s
>
> I put some print statement in all of the methods in UUIDField, and
> none of them are being called before that statement is executed,
> including: get_db_prep_lookup, get_db_prep_value, get_db_prep_save,
> pre_save
>
> The result is  an error from the database:
>
> <class 'psycopg2.ProgrammingError'>: can't adapt
>
> Interesting note... the psycopg driver doesn't generate an error.
> Even though it is an older driver, apparently is is less picky about
> the parameters.  Psycopg will accept a uuid object in the statement
> that fails and apperently psycopg2 wants it cast to a string.
>
> If anyone has an idea I would love to hear it.
>
> By the way, I'm using a modified version of the UUIDField from the
> django-extensions project.  This is one that uses a native uuid field
> for the database when the backend supports it (postgresql) and a
> charfield when the backend doesn't support it (others).  I did some
> tests and performance with postgresql is better with the native type
> (not suprising).
>
> --gordon

I suspect you have not set the subclass's metaclass to
models.SubfieldBase - see here:
http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#the-subfieldbase-metaclass

You need to do this to get any of the overridden methods to be called.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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