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

QueryBuilder fails when faces 3 layer deep relationships of certain kind #397

Closed
MeRuslan opened this issue Dec 12, 2022 · 2 comments
Closed

Comments

@MeRuslan
Copy link
Contributor

MeRuslan commented Dec 12, 2022

PGSync version:
2.3.3

Postgres version:
NA

Elasticsearch version:
NA

Redis version:
NA

Python version:
NA

Problem Description:
When there's base - one-to-one child - one to many with through kind of relationship, pgsync calls _non_through path for the one-to-one child which in turn tries to handle the one to many with through (which is a child of a first level one-to-one child) connection but fails,

It fails here, fails to find foreign keys
foreign_key_columns: list = self._get_column_foreign_keys( child._subquery.columns, foreign_keys, )

Maybe self._get_column_foreign_keys is not thorough enough to correctly link these entities in such a case.

Thus rendering pgsync not usable for that kind of a schema.

Not sure where exactly to fix it.

Error Message (if any):

    for i in range(len(foreign_key_columns)):
TypeError: object of type 'NoneType' has no len()

@MeRuslan
Copy link
Contributor Author

MeRuslan commented Dec 12, 2022

After giving it another look, it seems like table argument should be passed there, in which case it would resolve correctly.

            table = (
                child.relationship.throughs[0].table if child.relationship.throughs
                else None
            )
            foreign_key_columns: list = self._get_column_foreign_keys(
                child._subquery.columns,
                foreign_keys,
                table=table,
                schema=node.schema,
            )

That simple correction worked for me.
Would appreciate it if you @toluaina could have had a look.

@MeRuslan
Copy link
Contributor Author

working on a pr

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

No branches or pull requests

1 participant