flask-sqlalchemy icon indicating copy to clipboard operation
flask-sqlalchemy copied to clipboard

Using sqlalchemy.ext.compiler with BINDS

Open jawsthegame opened this issue 12 years ago • 1 comments

When using the compiles decorator as in this example:

http://docs.sqlalchemy.org/en/rel_0_8/core/compiler.html#compiling-sub-elements-of-a-custom-expression-construct

Queries constructed in this way do not seem to obey the bind_key in the info dictionary on the table.

In this code, I have added some debugging:

@compiler.compiles(InsertFromSelect)
   def visit_insert_from_select(element, compiler, **kwargs):
       print element.table.info
       return 'INSERT INTO %s %s' % (
           compiler.process(element.table, asfrom=True),
           compiler.process(element.select))

That info dictionary has the following value:

{"bind_key": "reporting"}

Which is the correct bind key. However, it is still attempting to query the default database specified in SQLALCHEMY_DATABASE_URI.

When I do a simple select('*', from_obj=[MY_TABLE]) this works as expected. It seems to be lost on the compiled stuff.

Any thoughts?

jawsthegame avatar Apr 10 '13 15:04 jawsthegame

May be related to #222.

kblomqvist avatar May 01 '16 06:05 kblomqvist

Assuming this is about metadata per bind, this would be fixed by #1087. Given the age, I'm going to close this, please reopen with a reproducible example if it's still an issue after that PR.

davidism avatar Sep 18 '22 16:09 davidism