We use SQLAlchemy to read/write data, but not create tables (as it done by 
DBAs). Due to this, some of the definitions which are incorrect, have not 
yet been caught (though it works for reads/writes etc.).

Is there a DRY way to to override them for testing purposes (create tables 
on the fly etc.), without touching the original definition? A simple 
class-overriding doesn't seem to work, and I don't see any other solution 
to this problem:

MRE:
from sqlalchemy import Column, Integer, Numeric, String
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Product(Base):
    __tablename__ = "product"

    idn = Column(Numeric, primary_key=True) # should be Integer
    code = Column(String, primary_key=True) # should be unique (not primary)

class Product(Product):
    __tablename__ = "product"
    __table_args__ = {"extend_existing": True} # want to override, not 
extend

    idn = Column(Integer, primary_key=True)
    code = Column(String, unique=True)

For now, my plan is to create a folder(file) called backlogs(.py) and dump 
these classes with a new Base. I will get it corrected in due time :-).

Thanks,
Nishant

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/00773483-19c1-482f-9743-9e318651b724n%40googlegroups.com.

Reply via email to