Skip to content

CreateService Session closes on failed create #52

Description

@valentinedwv

Adding tests based on @Castronova branch, and seeing that if a constraint is invalid, that the session becomes invalid.

Need to see check is the session is still open before attempting to create.

 # goal of this is to see that if we force errors like a null value, or duplicate that the session does not fail
# create some people
setup.odmcreate.createPerson(firstName="tony",
lastName='castronova',
middleName='michael')
with pytest.raises(Exception) as excinfo:
# this one should fail due to a not null constraint
setup.odmcreate.createPerson(firstName=None,
lastName='castronova',
middleName='michael')
assert 'People.PersonFirstName may not be NULL' in str(excinfo.value)
# now add again
setup.odmcreate.createPerson(firstName="tony",
lastName='castronova',
middleName=None)
2016-04-14 12:24:44,496 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2016-04-14 12:24:44,496 INFO sqlalchemy.engine.base.Engine INSERT INTO people (personfirstname, personmiddlename, personlastname) VALUES (?, ?, ?)
2016-04-14 12:24:44,496 INFO sqlalchemy.engine.base.Engine ('tony', 'michael', 'castronova')
2016-04-14 12:24:44,497 INFO sqlalchemy.engine.base.Engine COMMIT
2016-04-14 12:24:44,499 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2016-04-14 12:24:44,499 INFO sqlalchemy.engine.base.Engine INSERT INTO people (personfirstname, personmiddlename, personlastname) VALUES (?, ?, ?)
2016-04-14 12:24:44,499 INFO sqlalchemy.engine.base.Engine (None, 'michael', 'castronova')
2016-04-14 12:24:44,500 INFO sqlalchemy.engine.base.Engine ROLLBACK
F
setup = <class tests.test_odm2.odmConnection at 0x00000000088B34C8>
def test_SessionNotFailed(setup):
# goal of this is to see that if we force errors like a null value, or duplicate that the session does not fail
# create some people
setup.odmcreate.createPerson(firstName="tony",
lastName='castronova',
middleName='michael')
with pytest.raises(Exception) as excinfo:
# this one should fail due to a not null constraint
setup.odmcreate.createPerson(firstName=None,
lastName='castronova',
middleName='michael')
assert 'People.PersonFirstName may not be NULL' in str(excinfo.value)
# now add again
setup.odmcreate.createPerson(firstName="tony",
lastName='castronova',
> middleName=None)
tests\test_odm2.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
odm2api\ODM2\services\createService.py:226: in createPerson
self._session.commit()
build\bdist.win-amd64\egg\sqlalchemy\orm\session.py:801: in commit
???
build\bdist.win-amd64\egg\sqlalchemy\orm\session.py:390: in commit
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <sqlalchemy.orm.session.SessionTransaction object at 0x00000000088EC668>
prepared_ok = True, rollback_ok = False, deactive_ok = False
closed_msg = 'This transaction is closed'
> ???
E InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (sqlite3.IntegrityError) People.PersonFirstName may not be NULL [SQL: u'INSERT INTO people (personfirstname, personmiddlename, personlastname) VALUES (?, ?, ?)'] [parameters: (None, 'michael', 'castronova')]
build\bdist.win-amd64\egg\sqlalchemy\orm\session.py:214: InvalidRequestError

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions