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

Issue while adding views via sqlalchemy with autoload=True for Table class #15

Open
prathapreddy123 opened this issue May 6, 2017 · 0 comments

Comments

@prathapreddy123
Copy link

prathapreddy123 commented May 6, 2017

Step1:Create an instance with table_name bieng a view in database
Table(table_name, meta,schema=schema or None,
autoload=True,autoload_with=self.get_sqla_engine())
Above statement makes a call to Table class located in sqlalchemy.sql.schema module

Step2: Since autoload = True, this will try to load the column definitions and makes call to
engine.run_callable() method with callabale as reflecttable method in corresponding dialect class (in this example in DefaultDialect). This will create an inspector instance binding the current sqlalchemy engine and make a reflecttable call on inspector instance.

Step3: reflecttable call is routed to a method of Inspector class in sqlalchemy.engine.reflection module. This method makes various call to get columns, constrainsts such as primarykey,foreignkey,uniquekey and CheckConstraints.

Issue: During call to dialects get_check_constraints() with a view name, inside get_check_constraints
self.get_table_oid() method is called which just checks only for table. In case of view it raises NoSuchTableError()

Possible Resolution:
1.Do not make call to get_table_oid() method
2.Change the Query to check on schemaname and tablename instead of objectid (Same as in other constraint methods)
SELECT constraint_name, column_name
FROM v_catalog.constraint_columns
WHERE lower(table_schema) = '%(schema)s'
AND lower(table_name) = '%(table)s'
AND constraint_type = 'c'

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