Hello,
I am currently investigating whether all my current Python work/scripts
will work with Python 3 (v3.3.0). And I am running into an issue which
seems to be related to this. I have made an example (or actually took
the one from the documentation) to illustrate the issue.
Currently running Python 3.3.0 with SQLAlchemy 0.7.10 and cx_Oracle
5.1.2 (all 32 bit, on Windows)
-----
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker
# engine = create_engine('sqlite:///:memory:', echo=True)
engine = create_engine('oracle://scott:tiger@localhost:1521/xe',
echo=True)
Base = declarative_base()
Session = sessionmaker()
Session.configure(bind=engine)
session = Session()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String(32))
extra = Column(Integer, nullable=False)
def __init__(self, id, name, extra):
self.id = id
self.name = name
self.extra = extra
def __repr__(self):
return "<User('%d','%s', '%d')>" % (
self.id,
self.name,
self.extra)
Base.metadata.create_all(engine)
ed_user = User(2, 'Ed Jones', 2013)
session.add(ed_user)
session.commit()
-----
Not willing to be dependent on sequences required by Oracle I added the
id explicitly.
Running this script on 3.3 results in this error message:
sqlalchemy.exc.IntegrityError: (IntegrityError) ORA-01400: cannot insert
NULL into ("SCOTT"."USERS"."ID")
'INSERT INTO users (id, name, extra) VALUES (:id, :name, :extra)'
{'extra': 2013, 'name': 'Ed Jones', 'id': 2}
(more details available at request)
This seems odd, as the insert statement indicates the column id is
assigned with a correct value (2).
Same script, again Python 3, but now with SQLite (in memory): no errors.
Using Python 2 (v2.7.3) and Oracle; again no errors.
Is it correct to assume this would be related to SQLAlchemy?
Kind regards,
Thijs