[Sqlalchemy-tickets] Issue #4374: Feature Request: Issue warning when mapper discovers a member tha
Brought to you by:
zzzeek
From: Dave S. <iss...@bi...> - 2018-11-26 00:12:41
|
New issue 4374: Feature Request: Issue warning when mapper discovers a member that is a function. https://bitbucket.org/zzzeek/sqlalchemy/issues/4374/feature-request-issue-warning-when-mapper Dave Scotese: My code required a capital C in "Column" but I used a lower-case c, and this resulted in my database table NOT containing the column I defined. Ultimately, this appeared as "sqlalchemy.exc.NoForeignKeysError" because the column that didn't get put into my table is the foreign key. The code that reference the missing column may have created a problem that wasn't reported in the Werkzeug Traceback, or it may have been reported in a way that I didn't see. Here is the end of it: sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship Resource.locale - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression. I finally examined the database and discovered there was no column and traced that problem back to the bad letter case. I explored the two identifiers (Column and column): >>> import sqlalchemy >>> from sqlalchemy import create_engine >>> e = create_engine('sqlite:///:memory:', echo=True) >>> from sqlalchemy.ext.declarative import declarative_base >>> Base = declarative_base() >>> from sqlalchemy import Column, Integer, String File "<stdin>", line 1 from sqlalchemy import Column, Integer, String ^ IndentationError: unexpected indent >>> from sqlalchemy import Column, Integer, String >>> from sqlalchemy import column >>> column(Integer, primary_key=True) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: column() got an unexpected keyword argument 'primary_key' >>> column(Integer) <sqlalchemy.sql.elements.ColumnClause at 0x7f8acaeafac8; <class 'sqlalchemy.sql.sqltypes.Integer'>> >>> column <function column at 0x7f8acafccbf8> >>> Column <class 'sqlalchemy.sql.schema.Column'> So it seems that when SQLAlchemy examines a mapped class, it can find a member of the class that is a function ("column") or an instance of a class ("Column"), and it is silent in both cases. It may be useful to declare a member of a mapped class to be a function, but it seems it would be useful for SQLAlchemy to issue a warning when that happens. |