I ran into the following situation when using SQLAlchemy, and let me
explain using an example. Assume there is a table "Department", with three
columns: ID, name and charter, where ID is auto-generated by DB.
class Department(class_Base):
> __tablename__ = "department"
> id = Column(Integer, Sequence('department_id_seq'), primary_key=True)
> name = Column(String(250), nullable=False, unique=True)
> charter = Column(String(250), nullable=True)
> def __repr__(self):
> return "%s: id: [%d], name: [%s], charter: [%s]" %
> (self.__class__, self.id, self.name, self.charter)
Below is the skeleton of code:
> # step 1: grab a Department object using ORM
>
> # department name is unique
> l_department = g_session.query(Department).filter(Department.name ==
> in_department_name).one()
>
> # step 2: modify its charter using SQLExpression
> l_update_department = update(Department).where(Department.name ==
> in_department_name).values(charter=bindparam('charter'))
> l_update_department.execute({'charter': in_department_charter})
>
> # step 3: grab it again using ORM
> l_department = g_session.query(Department).filter(Department.name ==
> in_department_name).one()
What is unexpected is, the field "charter" is the same in step 1 and step
3, even though it is modified in step 2. The SQL statements in all three
steps are good, and the column "charter" indeed got updated per what I
checked from the database.
Question:
1. Is it something I should not do (mixing SQL expression and ORM)?
However, I did see it works in some cases.
2. Is it related to the database transactional capability? I am simply
testing against SQLite
Thanks!
--
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.