Comments (3)
It'd be nice if the package could interpret the query passed in, and translate it.
I'm not sure exactly what you mean "interpret the query passed in, and translate it."
Happy to accept a pull request with a failing test for this and the proposed fix.
from databases.
I did some more digging, and it seems the problem is with using SQLAlchemy's bindparam in a statement and passing the values to the values param. I get similar errors with using sa.select with a bindparam in it.
_build_query is what throws the exception, but I couldn't find where a ClauseElement has a method "values" on it.
I tried converting the query to a str then wrapping it in text to assign the bindparams
@staticmethod
def _build_query(
query: typing.Union[ClauseElement, str], values: dict = None
) -> ClauseElement:
if isinstance(query, str):
query = text(query)
return query.bindparams(**values) if values is not None else query
elif values:
try:
return query.values(**values)
except AttributeError as ex:
return text(str(query)).bindparams(**values)
return query
However, this introduced a different problem inside _compile method when attempting to use the fetch_one/fetch_all methods, where the compiled._result_columns would contain an empty list:
https://github.com/encode/databases/blob/master/databases/backends/postgres.py#L179
The data is still returned correctly, and you can access them via named keys, but the shorthand for dict() conversion of the returned asyncpg.Record object fails due to compiled._result_columns being empty when this package attempts to create an instance of it here (where it passes in an empty result_columns):
https://github.com/encode/databases/blob/master/databases/backends/postgres.py#L144
A workaround is to simply not use bindparam and let SQLAlchemy handle all the compiling without passing values into the execute/fetch methods of this package.
I'll keep poking around to see if I can find a better solution, but may just end up stop using bindparams in my statements.
from databases.
I think we've several issues with .bindparam
- https://github.com/encode/databases/search?q=bindparam&type=Issues (Specifically #79, #103)
Is there an easy way to detect if bindparam
has been used? Perhaps we ought to just raise a hard error in that case, and treat any bindparam
usage as currently being out of scope?
from databases.
Related Issues (20)
- Unable to retrieve foreignkey relation object from select statement HOT 2
- Password containing `/` cannot be used (MySQL)
- Support for UNIX domain socket for MySQL
- No module named 'asyncmy.connection' on python 3.11.3
- Warn for open transactions when a connection is garbage collected
- Unable to connect to database in docker
- MySQL Connection Pool Doesn't Seem to Work HOT 3
- Drop support for python 3.7 HOT 1
- New test `test_should_remove_ref_on_disconnect` in 0.8.0 fails on Fedora Linux HOT 10
- `IndexError` on force_rollback of Transaction in tests. HOT 13
- ImportError Postgresql HOT 1
- Transaction and gather HOT 2
- session manager/ session maker
- Allow passing string values for ssl query string in PostgreSQL URL HOT 1
- Version not match (0.8.0) depends on sqlalchemy (>=1.4.42,<1.5) HOT 2
- mypy's "has no attribute" error
- create table does not create unique keys and indexes
- new 0.8 version for sqlite connection with '?mode=ro' not working, Error can't open database
- Caching disabled in sqlalchemy queries HOT 1
- Potential Inefficiency in Connection Management Leading to "Too Many Connections" Error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from databases.