This should probably be filed as a bug since the docs(http://
www.djangoproject.com/documentation/custom_model_fields/) show an
example of raising a TypeError.

On May 11, 2:42 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> Hi gang (especially Malcolm, if you're listening),
>
> I was recently trying to test out a few things with field subclassing,
> and I made a PickleField just to see if I could. Basically, it pickles
> arbitrary Python objects for storage into the database, then unpickles
> them back into Python when accessed on a retrieved object. Everything
> worked fine until I decided to prevent any kind of filterin on the
> field, since there's no way to reliably compare pickled objects with
> each other.
>
> I thought it'd be easy, just writing PickleField.get_db_prep_lookup()
> to look like this:
>
> class PickleField(models.TextField):
>
>     # Unrelated  methods here...
>
>     def get_db_prep_lookup(self, lookup_type, value):
>         raise TypeError("Can't make comparisons against pickled data.")
>
> Unfortunately, this resulted in some very strange behavior that I
> can't account for. When I try to query against a model that has that
> field on it, there are two possible results, depending on *how* I use
> the QuerySet. If I just use list(qs), it returns an empty list,
> without raising my error. But if I try to iterate over it (using [x
> for x in qs], for instance), it raises my error just fine. However,
> when I raise a ValueError, it works fine in both cases.
>
> I've posted a full interactive session[1] that illustrates the
> problem. And yes, I do realize that in an interactive session, the
> models don't get real tables in the database. That just helps
> illustrate that even when the error does get suppressed, it still
> somehow short-circuits the process, so that the query never actually
> executes.
>
> So, I guess I have two questions. Why does list(qs) suppress the
> TypeError while [x for x in qs] doesn't? And why does ValueError work
> even when TypeError doesn't?
>
> -Gul
>
> [1]http://dpaste.com/hold/49362/
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to