I was trying to use a synonym to map a column through a setter/getter (with use of descriptor kwarg). I'm not sure if I'm doing this right, but I tried to copy/paste the example out of the documentation, and it didn't work. Could someone point out what I'm doing wrong or point me at a better way to do what I want? I've tried with 1.1.12 and 1.2.1 with python 2.7.
this is the entirety of what I'm trying to do: ------------------------------------------------------ from sqlalchemy.ext import declarative Base = declarative.declarative_base() from sqlalchemy import * from sqlalchemy.orm import synonym class MyClass(Base): __tablename__ = 'my_table' id = Column(Integer, primary_key=True) job_status = Column(String(50)) job_status = synonym("_job_status", map_column=True) ------------------------------------------------------ This fails because the synonym won't compile. It appears that the job_status Column value has been overridden by the synonym before it's had a chance to create the synonym to the original. It seems I can get around this by not using the map_column value and just renaming the column to _job_status, but I was hoping that using sqlalchemy.inspect(row_instance).attrs would only return job_status, and not _job_status (I'm not even sure if this is true, it was just a guess on how it might work and what I wanted to happen) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.py", line 64, in __init__ _as_declarative(cls, classname, cls.__dict__) File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/ext/declarative/base.py", line 88, in _as_declarative _MapperConfig.setup_mapping(cls, classname, dict_) File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/ext/declarative/base.py", line 116, in setup_mapping cfg_cls(cls_, classname, dict_) File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/ext/declarative/base.py", line 148, in __init__ self._early_mapping() File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/ext/declarative/base.py", line 151, in _early_mapping self.map() File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/ext/declarative/base.py", line 576, in map **self.mapper_args File "<string>", line 2, in mapper File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py", line 692, in __init__ self._configure_properties() File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py", line 1383, in _configure_properties self._configure_property(key, prop, False) File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py", line 1677, in _configure_property prop.set_parent(self, init) File "/virtualenv/workspace/local/lib/python2.7/site-packages/sqlalchemy/orm/descriptor_props.py", line 626, in set_parent % (self.name, parent.mapped_table.description, self.key)) sqlalchemy.exc.ArgumentError: Can't compile synonym '_job_status': no column on table 'my_table' named 'job_status' -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.