Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. from pony import orm
  2. from pony.orm.dbapiprovider import BoolConverter
  3.  
  4. class DALBoolConverter(BoolConverter):
  5. def validate(self, val, obj=None):
  6. print 'VALIDATOR', val, obj
  7. return val
  8.  
  9. def py2sql(self, val):
  10. print 'py2sql', val
  11. return 'T' if val else 'F'
  12.  
  13. def sql2py(self, val):
  14. print 'sql2py', val
  15. return True if val == 'T' else False
  16.  
  17. def sql_type(self):
  18. print 'sql_type'
  19. return 'CHAR(1)'
  20.  
  21. db.provider.converter_classes.append((bool, DALBoolConverter))
  22.  
  23. class AuthUser(db.Entity):
  24. _table_ = 'auth_user'
  25.  
  26. first_name = orm.Required(str)
  27. last_name = orm.Required(str)
  28. email = orm.Optional(str)
  29. password = orm.Optional(str)
  30. registration_key = orm.Optional(str)
  31. reset_password_key = orm.Optional(str)
  32. registration_id = orm.Optional(str)
  33. active = orm.Required(bool)
  34.  
  35. if __name__ == '__main__':
  36. with db_session:
  37. a = AuthUser[1]
  38. print a.active # returns True
  39. a.active = False
  40.  
  41. Traceback (most recent call last):
  42. File "/home/jim/dev/qlf/qlf/pony_model.py", line 720, in <module>
  43. """
  44. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 476, in __exit__
  45. db_session._commit_or_rollback(exc_type, exc, tb)
  46. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 490, in _commit_or_rollback
  47. commit()
  48. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 381, in commit
  49. rollback_and_reraise(sys.exc_info())
  50. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 370, in rollback_and_reraise
  51. reraise(*exc_info)
  52. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 379, in commit
  53. cache.flush()
  54. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 1888, in flush
  55. if obj is not None: obj._save_()
  56. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 5363, in _save_
  57. elif status == 'modified': obj._save_updated_()
  58. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 5272, in _save_updated_
  59. cursor = database._exec_sql(sql, arguments, start_transaction=True)
  60. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 945, in _exec_sql
  61. connection = cache.reconnect(e)
  62. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 1776, in reconnect
  63. if not provider.should_reconnect(exc): reraise(*sys.exc_info())
  64. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/core.py", line 943, in _exec_sql
  65. try: new_id = provider.execute(cursor, sql, arguments, returning_id)
  66. File "<auto generated wrapper of execute() function>", line 2, in execute
  67. File "/home/jim/.local/lib/python2.7/site-packages/pony/orm/dbapiprovider.py", line 61, in wrap_dbapi_exceptions
  68. raise OperationalError(e)
  69. pony.orm.dbapiprovider.OperationalError: (1292, "Truncated incorrect DOUBLE value: 'T '")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement