- changed status to resolved
imported modules cause problems in __init__ parameters
Issue #1143
resolved
In version 0.5.0beta3, if a module such as datetime or decimal is imported and used in a constructor as a default for a parameter an error like
NameError: name 'datetime' is not defined
is returned. The error is returned for both datetime and decimal. The workaround is to refer to the module in the body of the init function rather than in the parameters.
Some code that triggers the error:
import datetime
import sqlalchemy.ext.declarative
from sqlalchemy import *
Base = sqlalchemy.ext.declarative.declarative_base()
class Foo(Base):
__tablename__ = 'foo'
id = Column(Integer, primary_key=True)
bar = Column(Date)
def __init__(self, bar=datetime.date.today()):
self.bar = bar
Engine = sqlalchemy.create_engine('sqlite:///:memory:')
Base.metadata.create_all(Engine)
Hope this helps. Thanks.
Comments (2)
-
repo owner -
repo owner - removed milestone
Removing milestone: 0.5.0 (automated comment)
- Log in to comment
there was no ticket here so its not a duplicate, but the issue has been fixed in aba1c2b11828d20d091967a469dbaa5397659a31.