#1547 Problem with python 2.5 + sqlalchemy or sqlite3

10.4_(PowerPC)
closed-fixed
5
2016-03-11
2008-06-20
No

I had some weird problem with my fink installation of python 2.5.1-1 on my PowerBook OS X Tiger laptop. When I ran my test code on ubuntu or dmg distribution of python, the code works fine. Even if with fink python distribution it works when I use postgre sql db instead of sqlite (it doesn't matter if sqlite uses in memory or norman file db).

Problem comes up when metadata.create_all(), metadata.drop_all(), metadata.create_all() sequence is called (quite normal code in unit testing for zeroing database tables). After that pre compiled sql command doesn't seem to work.

System information:

area-12:~/ keisari$ fink --version python25
Package manager version: 0.27.6
Distribution version: 0.8.1.rsync powerpc

SQLAlchemy 0.4.6 from setuptools
python2.5.1-1 from fink

Test code and thrown exception:

------------------ sqlalchemy_sqlite_test.py ---------

# -*- coding: utf8 -*-
from sqlalchemy import *
from sqlalchemy.orm import *

class User(object):
pass

engine = create_engine('sqlite:///:memory:')
metadata = MetaData(engine)

users_table = Table('my_users', metadata,
Column('id', Integer, primary_key=True),
Column('login', Unicode(255), nullable=False, unique=True),
autoload=False, useexisting=True)

mapper(User, users_table)

def save_object(obj):
session = create_session()
session.save_or_update(obj)
session.flush()
session.expunge(obj)

def create_and_drop_world(login=u'test@x.invalid'):
metadata.create_all()
user = User()
user.login = login
save_object(user)
metadata.drop_all()

create_and_drop_world()
create_and_drop_world()

------------- exception --------

area-12:~/sqlite_problem keisari$ /sw/bin/python2.5 sqlalchemy_sqlite_error_debug.py
Traceback (most recent call last):
File "sqlalchemy_sqlite_error_debug.py", line 32, in <module>
create_and_drop_world()
File "sqlalchemy_sqlite_error_debug.py", line 28, in create_and_drop_world
save_object(user)
File "sqlalchemy_sqlite_error_debug.py", line 21, in save_object
session.flush()
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/orm/session.py", line 786, in flush
self.uow.flush(self, objects)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 233, in flush
flush_context.execute()
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 445, in execute
UOWExecutor().execute(self, tasks)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 930, in execute
self.execute_save_steps(trans, task)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 945, in execute_save_steps
self.save_objects(trans, task)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 936, in save_objects
task.mapper._save_obj(task.polymorphic_tosave_objects, trans)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/orm/mapper.py", line 1161, in _save_obj
c = connection.execute(statement.values(value_params), params)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/engine/base.py", line 844, in execute
return Connection.executors[c](self, object, multiparams, params)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/engine/base.py", line 895, in execute_clauseelement
return self._execute_compiled(elem.compile(dialect=self.dialect, column_keys=keys, inline=len(params) > 1), distilled_params=params)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/engine/base.py", line 907, in _execute_compiled
self.__execute_raw(context)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/engine/base.py", line 916, in __execute_raw
self._cursor_execute(context.cursor, context.statement, context.parameters[0], context=context)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/engine/base.py", line 960, in _cursor_execute
self._handle_dbapi_exception(e, statement, parameters, cursor)
File "/sw/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/sqlalchemy/engine/base.py", line 942, in _handle_dbapi_exception
raise exceptions.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect)
sqlalchemy.exceptions.IntegrityError: (IntegrityError) my_users.login may not be NULL u'INSERT INTO my_users (login) VALUES (?)' ['test@x.invalid']

Discussion

  • monipol

    monipol - 2009-03-14
    • assigned_to: nobody --> goatbar
     
  • Kurt Schwehr

    Kurt Schwehr - 2009-03-14

    This tracker item is pending response by the submitter; we
    cannot continue processing it before that happens. As a
    consequence, its status has been set to "Pending". It will
    automatically revert to "Open" once a new comment is made to
    this item. If no response is made within 14 days, it will
    automatically be closed.

    Thank you.

     
  • Kurt Schwehr

    Kurt Schwehr - 2009-03-14

    Thanks for the bug report.

    Please do a "fink selfupdate" and "fink install sqlalchemy-py25" so that you upgrade to sqlalchemy version 0.5.2. That might fix the problem. If it still fails with 0.5.2, please submit a new traceback.

    -kurt

     
  • Hanspeter Niederstrasser

    • status: open --> closed-fixed
     

Log in to post a comment.