In my current model User, I have a field "name" which cannot be null.
I try creating a user object, and adding it to the DBSession provided by Pyramid and submitting it with transaction, like so.
with transaction.manager:
u = models.User()
models.DBSession.add(u)
For those who don't use Pyramid, DBSession is:
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Now, in my transaction above, I do have a validation issue - I need to assign a name to User, but I didn't. However, instead of getting an error telling me "You need to assign your user a name!", I get this:
<ipython-input-5-47d9c0e393f7> in <module>()
2 u = models.User()
----> 3 models.DBSession.add(u)
4
/home/user/Projects/env/local/lib/python2.7/site-packages/transaction-1.4.1-py2.7.egg/transaction/_manager.pyc in __exit__(self, t, v, tb)
118 def __exit__(self, t, v, tb):
119 if v is None:
--> 120 self.commit()
121 else:
122 self.abort()
/home/user/Projects/env/local/lib/python2.7/site-packages/transaction-1.4.1-py2.7.egg/transaction/_manager.pyc in commit(self)
109 """ See ITransactionManager.
110 """
--> 111 return self.get().commit()
112
113 def abort(self):
/home/user/Projects/env/local/lib/python2.7/site-packages/transaction-1.4.1-py2.7.egg/transaction/_transaction.py in commit(self)
276 tb = None
277 try:
--> 278 t, v, tb = self._saveAndGetCommitishError()
279 self._callAfterCommitHooks(status=False)
280 reraise(t, v, tb)
/home/user/Projects/env/local/lib/python2.7/site-packages/transaction-1.4.1-py2.7.egg/transaction/_transaction.py in _saveAndGetCommitishError(self)
300 import pdb
301 pdb.set_trace()
--> 302 traceback.print_stack(sys._getframe(1), None, ft)
303 # Append the stack entries from here down to the exception.
304 traceback.print_tb(tb, None, ft)
/usr/lib/python2.7/traceback.py in print_stack(f, limit, file)
267 except ZeroDivisionError:
268 f = sys.exc_info()[2].tb_frame.f_back
--> 269 print_list(extract_stack(f, limit), file)
270
271 def format_stack(f=None, limit=None):
/usr/lib/python2.7/traceback.py in print_list(extracted_list, file)
23 ' File "%s", line %d, in %s' % (filename,lineno,name))
24 if line:
---> 25 _print(file, ' %s' % line.strip())
26
27 def format_list(extracted_list):
/usr/lib/python2.7/traceback.py in _print(file, str, terminator)
11
12 def _print(file, str='', terminator='\n'):
---> 13 file.write(str+terminator)
14
15
TypeError: 'unicode' does not have the buffer interface
I've found the issue at hand is that, somewhere, there's a python version 2 vs 3 incompatibility, shown here TypeError: 'str' does not support the buffer interface. I know SQLAlchemy supports python 3+, and so that's where the issue may be coming from.
Note that if I do my transaction correctly, no errors are thrown.
Is there any way of getting around this issue without having to overwrite code in traceback.py?