imported modules cause problems in __init__ parameters

Issue #1143 resolved
Former user created an issue

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)

  1. Log in to comment