You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, apologies for a lot of the details missing in this report; I've run into this issue while working on a unit test layer for a proprietary project at work, and I don't know how to reduce it to a small reproducible example, nor can I easily share a setup for you to access where the bug occurs. I'll be happy to provide any additional information you might need, if you can guide me in getting it for you.
I've run into a weird issue where query results are missing some, but not all fields when using reflected models based on SQLService declarative base, even though the database very much has them, and they're returned correctly when using a plain SQLAlchemy Table for the same query. This is the basic reflection setup we're using:
fromsqlalchemyimportMetaData, make_url, textfromsqlalchemy.ext.automapimportautomap_basefromsqlserviceimportDatabase, ModelBase, declarative_base@contextmanagerdefget_reflected_db(args):
url=get_db_url(args)
# Set up SQLService's enhanced declarative base together with Automap# for reflection of existing tables# See https://sqlservice.readthedocs.io/en/latest/model.html# and https://docs.sqlalchemy.org/en/20/orm/extensions/automap.htmllogger.info("Reflecting database {}", url)
metadata=MetaData()
Model=automap_base(declarative_base(ModelBase, metadata=metadata))
db=Database(url, model_class=Model)
try:
db.reflect()
# Invoke AutomapModel.prepare(autoload_with=db.engine)
yielddbfinally:
db.close()
This is for a DB unit testing framework (not sure if that matters, but including it here for completeness), where in one of the tests, I'm exercising a stored procedure for adding users, and it fails the verification step to confirm that the results when querying it back match what was passed in. That's where the weirdness begins:
As you can see, the value for accreditationnum is missing when querying through the model, even though it's definitely visible if I ask for it explicitly, or drop down to the raw Table object. The query SQL generated is identical, and manually querying the DB confirms that the results are there.
The text was updated successfully, but these errors were encountered:
mathrick
changed the title
SQLService models missing fields that are visible when to a plain SQLAlchemy query
SQLService models missing fields that are visible to a plain SQLAlchemy query
Sep 10, 2023
Hi, apologies for a lot of the details missing in this report; I've run into this issue while working on a unit test layer for a proprietary project at work, and I don't know how to reduce it to a small reproducible example, nor can I easily share a setup for you to access where the bug occurs. I'll be happy to provide any additional information you might need, if you can guide me in getting it for you.
I've run into a weird issue where query results are missing some, but not all fields when using reflected models based on SQLService declarative base, even though the database very much has them, and they're returned correctly when using a plain SQLAlchemy
Table
for the same query. This is the basic reflection setup we're using:This is for a DB unit testing framework (not sure if that matters, but including it here for completeness), where in one of the tests, I'm exercising a stored procedure for adding users, and it fails the verification step to confirm that the results when querying it back match what was passed in. That's where the weirdness begins:
As you can see, the value for
accreditationnum
is missing when querying through the model, even though it's definitely visible if I ask for it explicitly, or drop down to the rawTable
object. The query SQL generated is identical, and manually querying the DB confirms that the results are there.Environment used:
The text was updated successfully, but these errors were encountered: