On 7/10/14, 2:46 PM, Brian Findlay wrote:
> Sqlalchemy seems to be coercing the upper boundary to be exclusive.
> See below tests (will need to change postgres db if you want to run them).
>
>
>
> from sqlalchemy import *
> from sqlalchemy.orm import *
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.dialects.postgresql import INT4RANGE
> from psycopg2.extras import NumericRange
>
> Base = declarative_base()
>
> class Foo(Base):
> __tablename__ = 'foo'
> id = Column(Integer, primary_key=True)
> range = Column(INT4RANGE)
>
>
> e = create_engine("postgresql://[email protected]:5432/test", echo=True)
> Base.metadata.create_all(e)
>
> sess = Session(e)
>
> foo_one = Foo(id=1, range='[1, 10]')
> foo_two = Foo(id=2, range=NumericRange(lower=1, upper=10, bounds='[]'))
> sess.add_all([foo_one, foo_two])
> sess.commit()
>
> #foo_one = sess.query(Foo).filter_by(id=1).first()
> #foo_two = sess.query(Foo).filter_by(id=2).first()
>
> # These pass
> assert foo_one.range == foo_two.range
> assert foo_one.range.lower == foo_two.range.lower
> assert foo_one.range.upper == foo_two.range.upper
>
> # These fail
> assert foo_one.range == NumericRange(lower=1, upper=10, bounds='[]')
> assert foo_two.range == NumericRange(lower=1, upper=10, bounds='[]')
>
> # But this passes
> assert foo_two.range == NumericRange(lower=1, upper=11, bounds='[)')
I don't do the range types, if you create a bug report, chris withers
can be assigned and he'll get a note about it. Or figure out a PR for us.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.