I am seeing a behavior similar to Issue #3402 but it exists in SQLAlchemy 
1.0.6 and it involves using geoalchemy2.  I have filed an issue there but 
since it is behaving differently in sqlalchemy 0.9.3, I wanted to raise it 
here as well.

Test program:

import geoalchemy2 

 

from sqlalchemy import *
> from sqlalchemy.orm import *
> from sqlalchemy.ext.declarative import declarative_base 

 

Base = declarative_base()
> user = 'user'
> password = 'pword'
> host = 'localhost'
> port = '5432'
> db_name = 'dev'
> db_uri = 'postgresql+psycopg2://%s:%s@%s:%s/%s' % (user,
>                                                      password,
>                                                      host,
>                                                      port,
>                                                      db_name)
> engine = create_engine(db_uri)
> Base.metadata.create_all(engine)
>
> class A(Base):
>     __tablename__ = 'tests'
>     id = Column(Integer, primary_key=True)
>     geom = Column(geoalchemy2.Geometry('POLYGON'))
>
> s = Session(engine)
> A.__table__.create(engine)
> s.add(A(id = 1, geom='POLYGON((0 0,1 0,1 1,0 1,0 0))'))
> s.commit()
> a1 = s.query(A).first()
> a1.geom = None
> s.commit()
> A.__table__.drop(engine)

 
Trace: 

> Traceback (most recent call last):
>
  File "sqatest.py", line 38, in <module>
>     s.commit()
>   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
> line 790, in commit
>     self.transaction.commit()
>   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
> line 392, in commit
>     self._prepare_impl()
>   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
> line 372, in _prepare_impl
>     self.session.flush()
>   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
> line 2004, in flush
>     self._flush(objects)
>   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
> line 2122, in _flush
>     transaction.rollback(_capture_exception=True)
>   File 
> "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", 
> line 60, in __exit__
>     compat.reraise(exc_type, exc_value, exc_tb)
>   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
> line 2086, in _flush
>     flush_context.execute()
>   File 
> "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 
> 373, in execute
>     rec.execute(self)
>   File 
> "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 
> 532, in execute
>     uow
>   File 
> "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", 
> line 170, in save_obj
>     mapper, table, update)
>   File 
> "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", 
> line 630, in _emit_update_statements
>     lambda rec: (
>   File 
> "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", 
> line 459, in _collect_update_commands
>     value, state.committed_state[propkey]):
>   File 
> "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 
> 2726, in __bool__
>     raise TypeError("Boolean value of this clause is not defined")
> TypeError: Boolean value of this clause is not defined


This only happens when a 'geom' attribute is defined with a valid geometry 
and then assigned 'None' 

Assigning an initial geom value of None does not cause an issue. It also 
works fine as written in sqlalchemy 0.9.3 

I would love to know if this needs to be addressed in geoalchemy2 or is 
truly a sqlalchemy 1.0 

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to