<p dir="auto"><strong>Migrated issue, originally created by Michael Bayer (<a href="https://github.com/zzzeek">@zzzeek</a>)</strong></p>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">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</p>
<p dir="auto">NameError: name 'datetime' is not defined</p>
<p dir="auto">is returned.  The error is returned for both datetime and decimal.  The workaround is to refer to the module in the body of the <strong>init</strong> function rather than in the parameters.</p>
<p dir="auto">Some code that triggers the error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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)"><pre class="notranslate"><code class="notranslate">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)
</code></pre></div>
<p dir="auto">Hope this helps.<br>
Thanks.</p>