Thanks for the reply, Mike. In that case, I'll just keep a copy of our
definitions in the test case folder and correct them whenever required.
Hopefully, these will get merged to the real code sooner or later (which is
why I wanted to name it backlogs).

The goal is to stage tables(which are required)/data(ORM-style) required
for unit-testing our queries on a local SQL server
<https://hub.docker.com/_/microsoft-mssql-server>. It won't involve more
than 10-12 tables, usually. Such overridings also help in
development/debugging (add some cool features which are not needed in
production).

Regards,
Nishant

On Mon, 24 Oct 2022 at 23:47, Mike Bayer <mike...@zzzcomputing.com> wrote:

> I dont think there's an obvious way to override declarative classes like
> that, but I also dont understand the problem such that something like that
> would be necessary (that is, I dont understand why you need "create tables
> on the fly", is this in a local testing database where you *do* create
> tables?  not clear).   The original Product definition you have can be used
> directly with an existing database table that does not have exactly the
> same constraints or datatypes, whether or not there is actually a PK
> constraint covering "code".
>
> On Mon, Oct 24, 2022, at 12:16 PM, Nishant Varma wrote:
>
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/00773483-19c1-482f-9743-9e318651b724n%40googlegroups.com
> <https://groups.google.com/d/msgid/sqlalchemy/00773483-19c1-482f-9743-9e318651b724n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/aa577392-2c3e-4c18-b539-886743a5f0f6%40app.fastmail.com
> <https://groups.google.com/d/msgid/sqlalchemy/aa577392-2c3e-4c18-b539-886743a5f0f6%40app.fastmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAPy-swMJOpoAK4WqO7PWa9DD4BDJvXYj7TotX7H%3DL4fxpSy_Zg%40mail.gmail.com.

Reply via email to