[Sqlalchemy-tickets] Issue #3047: Errors when creating models are hidden (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Matthias U. <iss...@bi...> - 2014-05-10 20:19:30
|
New issue 3047: Errors when creating models are hidden https://bitbucket.org/zzzeek/sqlalchemy/issue/3047/errors-when-creating-models-are-hidden Matthias Urlichs: The problem I saw was that the _first_ access to MyDeclarativeTable.query returned None, but after that everything worked. I would like to actually see the error. I cannot understand why you're hiding it, in multiple places. The first is in lib/sqlalchemy/orm/scoping.py:query_property() where inside the query class you return None if there was an UnmappedClassError. The second is in sqlalchemy/orm/base.py:_inspect_mapped_class() where you return None upon catching exc.NO_STATE, which is an AttributeError, which neatly masks off the AttributeError that my model caused because of a typo. I submit that this makes no sense whatsoever, and I'd like to ask you to do something about these nonproductive try/except statements. They mask real problems. I can't see any practical use for them. This is what I did: ``` #!python Traceback (most recent call last): File "./manage.py", line 42, in <module> manager.run() File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 412, in run result = self.handle(sys.argv[0], sys.argv[1:]) File "/usr/lib/python2.7/dist-packages/flask_script/__init__.py", line 383, in handle res = handle(*args, **config) File "/daten/src/git/pip/pybble/pybble/manager/main.py", line 119, in __call__ return create_app(**kw) File "/daten/src/git/pip/pybble/pybble/app/__init__.py", line 342, in create_app site = Site.q.get_by(domain=text_type(site)) File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/scoping.py", line 130, in __get__ mapper = class_mapper(owner) File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py", line 383, in class_mapper raise exc.UnmappedClassError(class_) UnmappedClassError: Class 'pybble.core.models.site.Site' is not mapped > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(383)class_mapper() -> raise exc.UnmappedClassError(class_) (Pdb) q smurf@data:/daten/src/git/pip/pybble$ test/run.sh populate > /daten/src/git/pip/pybble/pybble/app/__init__.py(342)create_app() -> site = Site.q.get_by(domain=text_type(site)) (Pdb) b /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py:378 Breakpoint 1 at /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py:378 (Pdb) c > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(378)class_mapper() -> mapper = _inspect_mapped_class(class_, configure=configure) (Pdb) cl Clear all breaks? y (Pdb) s --Call-- > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(347)_inspect_mapped_class() -> @inspection._inspects(type) (Pdb) n > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(349)_inspect_mapped_class() -> try: (Pdb) > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(350)_inspect_mapped_class() -> class_manager = manager_of_class(class_) (Pdb) > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(351)_inspect_mapped_class() -> if not class_manager.is_mapped: (Pdb) > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(353)_inspect_mapped_class() -> mapper = class_manager.mapper (Pdb) > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(354)_inspect_mapped_class() -> if configure and mapper._new_mappers: (Pdb) > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(355)_inspect_mapped_class() -> mapper._configure_all() (Pdb) AttributeError: "type object 'SiteConfigVar' has no attribute 'name'" > /usr/lib/python2.7/dist-packages/sqlalchemy/orm/base.py(355)_inspect_mapped_class() -> mapper._configure_all() (Pdb) ``` It's not realistic to expect users to find their bugs by trial and error when Python has error handling which is perfectly capable of reporting exactly what went wrong. Removing these exception handlers is (mostly) straightforward. See the attached patch, which does not break any of the basic (sqlite) test cases. |