Tefnet Developers wrote:
sqlalchemy.orm.column_property(sqlalchemy.Column(sqlalchemy.types.Integer),
> extension = TefEx({0: 'Delivered', 1: 'Rejected', 2: 'Redirected', 3:
> 'Recipient dead'}))
>
> task = DeliveryTask()
>
> task.result = 3
> ========================================================
>
>
> An extension doesn't get inherited properly - a child class instance
> still uses parent class extension...
A few things here. First is, I'm not observing the extension not getting
inherited. Task().result = 3 raises the error, DeliveryTask().result = 3
does not, and the value is assigned to 3. This is with 0.5.5 as well as
trunk.
The second thing is, the approach is likely still incorrect. The Column()
object represents the physical column in the database, so in this approach
the DeliveryTask table will get its own column named "result", and I get
the impression you're looking to have two different validators for the
same column on the base table. So the sub column_property() needs to
reference the original Column:
class Task(Base):
Id = sqlalchemy.Column( sqlalchemy.types.Integer,
primary_key=True,autoincrement=True)
objectType = sqlalchemy.Column(
sqlalchemy.types.String(128),nullable=False)
__mapper_args__ = {'polymorphic_on': objectType}
result
=sqlalchemy.orm.column_property(sqlalchemy.Column(sqlalchemy.types.Integer),
extension = TefEx({0: 'Success', 1: 'Failure'}))
class DeliveryTask(Task):
Id = sqlalchemy.Column( sqlalchemy.types.Integer,
sqlalchemy.ForeignKey(Task.Id), primary_key=True,autoincrement=True)
result =sqlalchemy.orm.column_property(Task.result, extension =
TefEx({0: 'Delivered', 1: 'Rejected', 2: 'Redirected', 3:
'Recipientdead'}))
What I think is even simpler is to have the extension or validator just
look at the class itself for the desired state:
class Task(Base):
Id = sqlalchemy.Column( sqlalchemy.types.Integer,
primary_key=True,autoincrement=True)
objectType = sqlalchemy.Column(
sqlalchemy.types.String(128),nullable=False)
result = sqlalchemy.Column(sqlalchemy.types.Integer)
__mapper_args__ = {'polymorphic_on': objectType}
enumDict = {0: 'Success', 1: 'Failure'}
@validates('result')
def set(self, key, value):
import sys; sys.stderr.write("SET %s on %s\n" %
(value,self.enumDict))
if value not in self.enumDict.keys():
raise ValueError("value %s not in %s" % (value,self.enumDict))
return value
class DeliveryTask(Task):
Id = sqlalchemy.Column( sqlalchemy.types.Integer,
sqlalchemy.ForeignKey(Task.Id), primary_key=True,autoincrement=True)
enumDict = {0: 'Delivered', 1: 'Rejected', 2: 'Redirected', 3:
'Recipientdead'}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---