Hey sqlalchemy,

It's common in our code to have encrypted columns:

class Patient(Base):
  first_name = Column(LargeBinary, ..)

In order to figure out what key we use to decrypt the first_name column, we 
may need to do a lookup using the whole row. 

def get_encryption_key(self):
  session.query(HealthcareProviderDataKey).filter(..)

Currently, we have, on our base class, a Base.get(key) method that may call 
self.get_encryption_key() and do some decryption, so to read a patient's 
first name, I might call patient.get('first_name').

Instead, the docs suggest we could use the @hybrid_propery decorator and 
alias the column property:

class Patient(Base):
  _first_name = Column("first_name", LargeBinary, ..)

  @property
  def first_name(self):
    self.decrypt(self._first_name)

That's great, but is a bit tedious/verbose to do for each of our encrypted 
columns. Ideally I'd be able to declare the column as a custom type, or set 
a key in the column "info" dict..

Is there a recommended way to override the getattr behavior for columns 
like this? 

I don't think I can just use TypeDecorator because I need access to the 
whole row, and I haven't quite been able to get overriding __getattr__ on 
the declarative metaclass to work..

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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.

Reply via email to