FormAlchemy / pyramid_formalchemy

44 stars 14 forks source link

ImportError: cannot import name exceptions #27

Closed tonthon closed 11 years ago

tonthon commented 11 years ago

Using SQLAlchemy==0.8.0b2 with pyramid-formalchemy==0.4.3 , I get the following error:

File "/.../lib/python2.7/site-packages/pyramid_formalchemy/resources.py", line 4, in <module>
    from sqlalchemy import exceptions as sqlalchemy_exceptions
ImportError: cannot import name exceptions

The exception module has been moved to sqlalchemy.exc, so the following

from sqlalchemy import exc as sqlalchemy_exceptions

makes it work

hirokiky commented 11 years ago

+1. I met with this problem too.

I seems good to use try:...except for backward compatibility like::

try:
    from sqlalchemy import exceptions as sqlalchemy_exceptions
except ImportError:
    from sqlalchemy import exc as sqlalchemy_exceptions

What do you say?

tonthon commented 11 years ago

The following could already be find in sqlalchemy 0.7.0 in the init.py file:

import sqlalchemy.exc as exceptions

It has to be verified but if formalchemy 1.4.2 depends on sqlalchemy >= 0.7 as the actual version does, no try except is needed.(pyramid_formalchemy depends on formalchemy >= 1.4.2).

hirokiky commented 11 years ago

tonthon, Thanks for your comment. I completely understood about it. In sqlalchymy 0.7, we can use both 'exc' and 'exceptions', but in 0.8.0b2, we can't use 'exceptions'.