Hi all,

I've got a module defining a number of abstract declarative classes.  They 
represent standard generic classes/tables.  
I'd like to take one of these abstract classes and subclass more than once, 
adding a 'schema' name to '__table_args__' and a '__tablename__'.  This to 
me is like making a specific 'realization' of the abstract class structure. 
 I want to keep the columns (with info dictionaries) and constraints in the 
abstract class, but make a 'realization' of the abstract class as different 
tables with different names and schema.  

When I do this, however, I get warnings and errors I don't understand. Here's 
an example:

% ------------------------  code 
 --------------------------------------------------------------------------
from sqlalchemy import Column, Numeric, String, Date, PrimaryKeyConstraint
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Students(Base):
    __abstract__ = True
    __table_args__ = (PrimaryKeyConstraint(u'stid', u'last_name'),)

    stid = Column(Numeric(9, 0, False), nullable=False, info={'format': 
'9.2f'})
    first_name = Column(String(30), info={'format': '30.30s'})
    last_name = Column(String(30), info={'format': '30.30s'})
    description = Column(String(80), info={'format': '80.80s'})
    lddate = Column(Date, info={'format': '%Y-%m-%d %H:%M:%S'})


class MyStudents(Students):
    __tablename__ = 'students'
    __table_args__ = Students.__table_args__ + ({'__schema__': 'me'},)

class OldStudents(Students):
    __tablename__ = 'oldstudents'
    __table_args__ = Students.__table_args__ + ({'__schema__': 'me'},)

class OtherStudents(Students):
    __tablename__ = 'students'
    __table_args__ = Students.__table_args__ + ({'__schema__': 'other'},)
% ------------------------  end code 
 -----------------------------------------------------------------------

1) The abstract declaration goes fine.  So does declaring MyStudents.
2) When I declare OldStudents, I get the following warning.  Why do I get 
this? I thought I was creating things, not replacing anything.

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/sqlalchemy/sql/expression.py:2477:
 
SAWarning: Column 'stid' on table Table('students', MetaData(bind=None), 
Column('stid', Numeric(precision=9, scale=0, asdecimal=False), 
table=<students>, primary_key=True, nullable=False), Column('first_name', 
String(length=30), table=<students>), Column('last_name', 
String(length=30), table=<students>, primary_key=True), 
Column('description', String(length=80), table=<students>), 
Column('lddate', Date(), table=<students>), schema=None) being replaced by 
Column('stid', Numeric(precision=9, scale=0, asdecimal=False), 
table=<oldstudents>, nullable=False), which has the same key.  Consider 
use_labels for select() statements.
  self[column.key] = column
/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/sqlalchemy/sql/expression.py:2477:
 
SAWarning: Column 'last_name' on table Table('students', 
MetaData(bind=None), Column('stid', Numeric(precision=9, scale=0, 
asdecimal=False), table=<students>, primary_key=True, nullable=False), 
Column('first_name', String(length=30), table=<students>), 
Column('last_name', String(length=30), table=<students>, primary_key=True), 
Column('description', String(length=80), table=<students>), 
Column('lddate', Date(), table=<students>), schema=None) being replaced by 
Column('last_name', String(length=30), table=<oldstudents>), which has the 
same key.  Consider use_labels for select() statements.
  self[column.key] = column

3) When I declare OtherStudents (it was just a warning, after all), I get 
the following error.  Again, I thought I was creating things, not replacing 
anything.  Is 'schema' not part of the registry?

InvalidRequestError: Table 'students' is already defined for this MetaData 
instance.  Specify 'extend_existing=True' to redefine options and columns 
on an existing Table object.

I just want to be able to create & query a class called MyStudents that 
points to a table called 'students' on the 'me' Oracle account, OldStudents 
that points to the 'oldstudents' table on the 'me' account, and 
OtherStudents that points to the 'students' table on the 'other' account. 
 All these tables look the same, and I thought this is what abstract 
classes where for.

Am I using the wrong bit of SQLAlchemy machinery?  If so, could someone 
point me to the right bit?  I feel like I'm not quite grokking 
abstract/concrete table inheritance.

Thanks for your time,
Jon

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to