[Sqlalchemy-tickets] [sqlalchemy] #2734: __eq__ operator appears to not be working correctly for de
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-05-29 15:26:14
|
#2734: __eq__ operator appears to not be working correctly for decorated types
---------------------------+-----------------------------------------
Reporter: mcclurem | Owner: zzzeek
Type: defect | Status: new
Priority: medium | Milestone:
Component: declarative | Severity: no triage selected yet
Keywords: TypeDecorator | Progress State: awaiting triage
---------------------------+-----------------------------------------
So from the documentation it makes it appear that by defining
`process_bind_param` and `process_result_value` I should have all the
workings to transparently perform a translation. However the == operator
doesn't perform the translation before sending the query to the db.
Here's my example:
{{{
#!div style="font-size: 80%"
{{{#!python
class NullableString(TypeDecorator):
'''Turns None into the string "Null" and back in order to prevent
Null!=Null issues'''
impl = String
def process_bind_param(self, value, dialect):
return "NONE" if value is None else value
def process_result_value(self, value, dialect):
return None if value == "NONE" else value
}}}
}}}
If I have a class `SomeType` and I perform the following:
{{{
#!div style="font-size: 80%"
{{{#!python
session.query(SomeType).filter(SomeType.nullableStringCol ==
None).all()
}}}
}}}
I get no results but if I do:
{{{
#!div style="font-size: 80%"
{{{#!python
session.query(SomeType).filter(SomeType.nullableStringCol ==
"NONE").all()
}}}
}}}
I get my results.
Now I can get around this by declaring the instance of the
`NullableString` to use a custom comparator in `SomeType` but that seems
like a broken paradigm because that comparison behavior should be captive
within my new type.
Am I misunderstanding the mechanism for the comparison?
I apologize if this isn't a bug but it seems like it's broken (the example
of typedecorators in the docs would presumably suffer the same problem
when comparing unicode strings)
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2734>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|