Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect Via metadata failing #751

Open
maestro-1 opened this issue Jan 6, 2021 · 2 comments
Open

Reflect Via metadata failing #751

maestro-1 opened this issue Jan 6, 2021 · 2 comments
Labels
bug Describes a bug in the system.

Comments

@maestro-1
Copy link

maestro-1 commented Jan 6, 2021

Describe the bug
In using gino I tried to use the reflect, but it fails. I speculate this is because it runs as a default sqlalchemy function rather than a gino spinoff, but since it is a gino engine it fails.
To Reproduce
Please provide a self-contained script to reproduce the bug if possible.

from gino import Gino

db = Gino()

#I tried 
loop.run_until_complete(db.reflect())

#also tried  
db.reflect()

result

AttributeError: 'GinoEngine' object has no attribute 'connect'

Now for good measure, I tried a few other alternatives

from gino import Gino
db = Gino
db.gino._item.reflect()

The result was the same.

I need to e able to retrieve metadata from the database without having prior knowledge of items in it. Things like all the available tables. All the columns in a specified table and so on. Gino does not seem to support these key features. I would have proceeded to do this with sqlalchemy, but seeing that I am already using gino(and gino engine) I cannot because sqlalchemy does not recognize gino engines hence features like reflect, inspect and engine.dialect.get_table_names are not available in gino.
Now there is the option of creating one sqlalchemy engine and one gino engine for the same database but then that seems counterintuitive.
All the fails stem from variation in function names like connect instead of acquire except for dialect.get_table_name which is completely unavailable

Environment (please complete the following information):

  • GINO: [e.g. 1.0.1]
  • SQLAlchemy: [e.g. 1.3.10]
  • Linux, PostgreSQL 10, asyncpg 0.21

Additional context
Add any other context about the problem here.

@fantix
Copy link
Member

fantix commented Mar 21, 2021

Hmm the reflect() was not supposed to work - it was probably a bad idea to simply inherit and expose such SQLAlchemy sync methods without specification, but that ship has sailed.

I haven't tried but I do think this will be in a better shape for v1.4 as SQLAlchemy 1.4 will support async natively, and we could somehow get that for free. In other words, this won't be fixed in GINO <1.4.

As a workaround, I'd suggest using something like e = sa.create_engine(); loop.call_in_executor(None, db.reflect, bind=e) to solve your current problem, as I would assume reflection is not something that'll be called frequently in runtime, so asynchronous is not a top priority.

@maestro-1
Copy link
Author

This was just an illustration of a major underlying problem with the gino API(which I am currently working to fix). Reflect is definitely not the best example to have used, however gino inherits certain classes from SQLAlchemy but because of the difference in API for the connection and engine of both of them, GINO will throw an error, which is as a result of the code itself within GINO and not any users fault.
I noticed this problem when trying to work with Gino dialect classes.
I do intend to make use of SQLAlchemy 1.4 and above in the future, but it will be also be nice to have an alternative: GINO, without having this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Describes a bug in the system.
Projects
None yet
Development

No branches or pull requests

2 participants