I'm using SQLAlchemy 1.0.13 with Python 2.7.10.
I load much of my data naively from text files, which means that for
newly-created Declarative objects, all the values are strings, whatever the
declared column type:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
Base = declarative_base()
class Organization(Base):
__tablename__ = 'organizations'
id = Column(Integer, primary_key=True)
org_type_id = Column(Integer, nullable=False)
org_name = Column(String(255), nullable=False)
org = Organization(**{
'org_type_id' : '3',
'org_name' : 'Type 3',
})
If the Organization object is added to the database, the org_type_id value
is converted to an 'int'. However, if I need to compare an object already
in the database with the newly instantiated one, the comparison always
fails because the int 3 from the database isn't the same as the string '3'
in the new object.
Is there a way to force the newly-created Organization to cast the string
'3' to an Integer/int without having to push it to the database? I'd much
prefer doing things this way to writing conversion functions for loading
that attempt to anticipate all the permutations incoming data (e.g.
date/times, numerics) might take. In other words, I'd like to use the
existing machinery, but have the converted values show up before adding the
object to the database.
Thanks in advance.
Chuck
--
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.