I’m trying to setup tests for my project and want to use an in memory database for those tests. Based on some examples I found online I’ve been able to get an in memory sqlite database working… The problem I have is my models are all based around MSSQL (that’s what the ‘real’ code is using) so I get E
Tag: sqlalchemy
difference between autobegin and Session.begin
In the following code snippet a commit is executed once the with block is exited. As per the docs https://docs.sqlalchemy.org/en/20/orm/session_api.html#sqlalchemy.orm.Session.begin The Session object features autobegin behavior, so that normally it is not necessary to call the Session.begin() method explicitly Running without begin, like so does not commit even though the docs mention autobegin is not needed. The docs for Session.begin
Flask-SQLAlchemy Legacy vs New Query Interface
I am trying to update some queries in a web application because as stated in Flask-SQLAlchemy I have a query: Which is translated into: And I take the subnets variable and loop it over in my view in two different locations. And it works. However, when I try to update my query and use the new SQLAlchemy interface: I can
How can I effectively use the same orm model in two git repositories?
The initial situation is that I have two fast-api servers that access the same database. One is the real service for my application and the other is a service for loading data from different sources. Both services have their own Github repository, but use the same orm data model. My question is: What are best practices to manage this orm
FASTAPI SQLAlchemy Creating a table during run time based on user input
The user will be providing some information such as table_x with column_x. And I’d like to create these tables in an existing database or a new database based on the user’s value. These values will be provided during run-time therefore I cannot create the Model beforehand. If anyone could provide some help, let me know! Answer I’ve managed to figure
ImportError: cannot import name ‘_rfc_1738_quote’ from ‘sqlalchemy.engine.url’
I am using a python snowflake connector from the following package: snowflake-sqlalchemy It used to be working but it’s now failing with this weird error. I tried to switch to older version of the package, but can’t get rid of this error. Here is the fulll stack trace: Answer Looks like this is a known issue will get resolved in
SQLAlchemy / mysql – How to insert data without calculated (computed) columns
I have a calculated (computed) column in a table and would like to insert rows with the calculated column not specified with SQLAlchemy. However, the SQL query for insert generated by SQLAlchemy includes the calculated column. Is there a way not to specify a column in this case? Please refer to the following. Answer It looks like mysql accepts “DEFAULT”
SQLAlchemy returns script parameters instead of script results
I’m trying to use SQLAlchemy 1.4 to query an Oracle database: This should return some kind of datetime object. When I execute this code (roughly) using SQLAlchemy, it decides to return the value of the :created_date parameter instead. Why is the result (literally) “blah”? EDIT:: See snakecharmerb’s answer below; you can’t bind column or table names with SQLAlchemy. It’s a
SQLAlchemy How to create a composite index between a polymorphic class and it’s subclass
I am trying to get a composite index working between a polymorphic subclass and it’s parent. Alembic autogenerate does not seem to detect Indexes outside of __table_args__. I can’t use __table_args__ because, being in the subclass, it does not count my class as having a __table__. How do I create a composite Index between these? The goal is to have
Flask admin – complex sort on hybrid_property
I have a fairly complex hybrid_property. This is a vendor model, which has multiple skuchannels (products). What it does is: Based on the target_stock_duration (e.g. we want to keep items in stock for 4 months) calculate how many units have to be ordered and how much this would cost. This gives us the potential. well this hybrid_property works just fine,