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

Query returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually. #238

Open
adrianschneider94 opened this issue Mar 12, 2020 · 4 comments · May be fixed by #280

Comments

@adrianschneider94
Copy link

adrianschneider94 commented Mar 12, 2020

Hi,

when I try to query a relationship of a verison object like that:

x = session.query(InventoryItem).first()
print(x.versions[2].node)

I always get the following error:

FROM "~nodes", nodes, inventory_item 
WHERE "~nodes".transaction_id <= :transaction_id_1 AND nodes.id = inventory_item.id' returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually.

I have this behaviour is on all classes -- what can I do?

Thanks for your great work in the SQLAlchemy community!

Best wishes
Adrian Schneider

@adrianschneider94
Copy link
Author

The problem is somehow connected to the tablename.
I set the tablename to ~%s with

options={'table_name': '~%s'},

to let the history tables appear after the normal ones when sorting alphabetically.

But apparently this does not work.

@aditya051293
Copy link

aditya051293 commented Jul 1, 2022

@adrianschneider94 did you get any solution for this?
I am facing the same issue.
model entity and model key are both versioned .

Class entity():
    __versioned__ = {}
   id = .....
   key_id = ...foreign_key to key table...
   key = relationship(key)

Class key():
   __versioned__ = {}
   id
   ....... 
ent = session.query(entity).first()
ent.versions[2].key

Gave me the error on similar lines.
Select statement '<sqlalchemy.sql.selectable.Select object at 0x7f7fb88b1ef0>' returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually.

Issue arises for below settings in options
options={'table_name': '%s_trace'},

@aditya051293
Copy link

aditya051293 commented Jul 1, 2022

Looks like

def version_table(table):

This function is hardcoding '<table_name>_version' to the traking table name, and not taking the table name that is set from the option.
Causing this issue

@aditya051293
Copy link

aditya051293 commented Aug 9, 2022

overriding the version_table function worked for me as a temporary fix


from sqlalchemy_continuum import expression_reflector, utils as continuum_utils

trace_suffix = '_trace'
def version_table(table):
    if table.schema:
        return table.metadata.tables[table.schema + '.' + table.name + trace_suffix]
    elif table.metadata.schema:
        return table.metadata.tables[table.metadata.schema + '.' + table.name + trace_suffix]
    else:
        return table.metadata.tables[table.name + trace_suffix]

continuum_utils.version_table = version_table
expression_reflector.version_table = version_table

make_versioned(user_cls=None, options={'table_name': f'%s{trace_suffix}'})

indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Aug 15, 2022
marksteward pushed a commit that referenced this issue Aug 28, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Aug 31, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 11, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 11, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 11, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 15, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 15, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants