Skip to content

Instantly share code, notes, and snippets.

@silenius
Created April 10, 2018 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silenius/561b13f4b987c36434cd81e2c08cab6e to your computer and use it in GitHub Desktop.
Save silenius/561b13f4b987c36434cd81e2c08cab6e to your computer and use it in GitHub Desktop.
>>> from amnesia.modules.document import DocumentTranslation
>>> a = request.dbsession.query(Document).get(100)
2018-04-10 15:08:13,038 INFO [sqlalchemy.engine.base.Engine][MainThread] BEGIN (implicit)
2018-04-10 15:08:13,042 INFO [sqlalchemy.engine.base.Engine][MainThread] SELECT content.id AS content_id, content.added AS content_added, content.updated AS content_updated, content.effective AS content_effective, content.expiration AS content_expiration, content.exclude_nav AS content_exclude_nav, content.weight AS content_weight, content.content_type_id AS content_content_type_
id, content.container_id AS content_container_id, content.owner_id AS content_owner_id, content.state_id AS content_state_id, content.is_fts AS content_is_fts, content.props AS content_props, document.content_id AS document_content_id, state_1.id AS state_1_id, state_1.name AS state_1_name, account_1.id AS account_1_id, account_1.login AS account_1_login, account_1.password AS acc
ount_1_password, account_1.name AS account_1_name, account_1.first_name AS account_1_first_name, account_1.email AS account_1_email, account_1.enabled AS account_1_enabled, account_1.created AS account_1_created, account_1.picture AS account_1_picture, account_1.lost_token AS account_1_lost_token, language_1.id AS language_1_id, language_1.name AS language_1_name, content_1.id AS
content_1_id, content_1.added AS content_1_added, content_1.updated AS content_1_updated, content_1.effective AS content_1_effective, content_1.expiration AS content_1_expiration, content_1.exclude_nav AS content_1_exclude_nav, content_1.weight AS content_1_weight, content_1.content_type_id AS content_1_content_type_id, content_1.container_id AS content_1_container_id, content_1.o
wner_id AS content_1_owner_id, content_1.state_id AS content_1_state_id, content_1.is_fts AS content_1_is_fts, content_1.props AS content_1_props, content_translation_1.language_id AS content_translation_1_language_id, content_translation_1.content_id AS content_translation_1_content_id, content_translation_1.title AS content_translation_1_title, content_translation_1.description
AS content_translation_1_description, content_translation_1.fts AS content_translation_1_fts, content_type_1.id AS content_type_1_id, content_type_1.name AS content_type_1_name, content_type_1.description AS content_type_1_description, content_type_1.icons AS content_type_1_icons
FROM content JOIN document ON content.id = document.content_id JOIN state AS state_1 ON state_1.id = content.state_id JOIN account AS account_1 ON account_1.id = content.owner_id JOIN (content AS content_1 JOIN content_translation AS content_translation_1 ON content_1.id = content_translation_1.content_id) ON content_translation_1.content_id = content.id AND content_translation_1.
language_id = %(param_1)s JOIN language AS language_1 ON language_1.id = content_translation_1.language_id JOIN content_type AS content_type_1 ON content_type_1.id = content.content_type_id
WHERE content.id = %(param_2)s
2018-04-10 15:08:13,043 INFO [sqlalchemy.engine.base.Engine][MainThread] {'param_2': 100, 'param_1': 'en'}
2018-04-10 15:08:13,057 INFO [sqlalchemy.engine.base.Engine][MainThread] SELECT content.id AS content_id, content.added AS content_added, content.updated AS content_updated, content.effective AS content_effective, content.expiration AS content_expiration, content.exclude_nav AS content_exclude_nav, content.weight AS content_weight, content.content_type_id AS content_content_type_
id, content.container_id AS content_container_id, content.owner_id AS content_owner_id, content.state_id AS content_state_id, content.is_fts AS content_is_fts, content.props AS content_props, content_translation.language_id AS content_translation_language_id, content_translation.content_id AS content_translation_content_id, content_translation.title AS content_translation_title, c
ontent_translation.description AS content_translation_description, content_translation.fts AS content_translation_fts, anon_1.content_id AS anon_1_content_id, language_1.id AS language_1_id, language_1.name AS language_1_name
FROM (SELECT content.id AS content_id
FROM content JOIN document ON content.id = document.content_id
WHERE content.id = %(param_1)s) AS anon_1 JOIN (content JOIN content_translation ON content.id = content_translation.content_id) ON anon_1.content_id = content_translation.content_id JOIN language AS language_1 ON language_1.id = content_translation.language_id ORDER BY anon_1.content_id
2018-04-10 15:08:13,057 INFO [sqlalchemy.engine.base.Engine][MainThread] {'param_1': 100}
>>> a
<Document:100>
>>> a.translations
{'en': <amnesia.modules.document.model.DocumentTranslation object at 0x80bc36ef0>}
>>> a.translations['en']
<amnesia.modules.document.model.DocumentTranslation object at 0x80bc36ef0>
>>> b = DocumentTranslation(content=a, language_id='fr', title='lol', description='lol123', body='foo')
>>> request.dbsession.add(b)
>>> request.dbsession.flush()
2018-04-10 15:09:55,268 INFO [sqlalchemy.engine.base.Engine][MainThread] UPDATE content SET updated=%(updated)s WHERE content.id = %(content_id)s
2018-04-10 15:09:55,268 INFO [sqlalchemy.engine.base.Engine][MainThread] {'content_id': 100, 'updated': datetime.datetime(2018, 4, 10, 15, 9, 55, 266733, tzinfo=<DstTzInfo 'Europe/Brussels' CEST+2:00:00 DST>)}
2018-04-10 15:09:55,273 INFO [sqlalchemy.engine.base.Engine][MainThread] INSERT INTO content (updated, effective, expiration, weight, content_type_id, container_id, owner_id, state_id) VALUES (%(updated)s, %(effective)s, %(expiration)s, %(weight)s, %(content_type_id)s, %(container_id)s, %(owner_id)s, %(state_id)s) RETURNING content.id
2018-04-10 15:09:55,273 INFO [sqlalchemy.engine.base.Engine][MainThread] {'updated': None, 'content_type_id': 8, 'container_id': None, 'state_id': None, 'weight': None, 'effective': None, 'owner_id': None, 'expiration': None}
2018-04-10 15:09:55,275 INFO [sqlalchemy.engine.base.Engine][MainThread] ROLLBACK
Traceback (most recent call last):
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 507, in do_execute
cursor.execute(statement, parameters)
psycopg2.IntegrityError: null value in column "owner_id" violates not-null constraint
DETAIL: Failing row contains (4122, 2018-04-10 15:08:13.04424+02, null, null, null, f, 1, 8, null, null, null, t, null).
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2254, in flush
self._flush(objects)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2380, in _flush
transaction.rollback(_capture_exception=True)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 187, in reraise
raise value
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2344, in _flush
flush_context.execute()
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py", line 391, in execute
rec.execute(self)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py", line 556, in execute
uow
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py", line 181, in save_obj
mapper, table, insert)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py", line 866, in _emit_insert_statements
execute(statement, params)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 948, in execute
return meth(self, multiparams, params)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/sql/elements.py", line 269, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1060, in _execute_clauseelement
compiled_sql, distilled_params
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context
context)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
exc_info
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/usr/home/jcigar/code/venvs/amnesiacms/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 507, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) null value in column "owner_id" violates not-null constraint
DETAIL: Failing row contains (4122, 2018-04-10 15:08:13.04424+02, null, null, null, f, 1, 8, null, null, null, t, null).
[SQL: 'INSERT INTO content (updated, effective, expiration, weight, content_type_id, container_id, owner_id, state_id) VALUES (%(updated)s, %(effective)s, %(expiration)s, %(weight)s, %(content_type_id)s, %(container_id)s, %(owner_id)s, %(state_id)s) RETURNING content.id'] [parameters: {'updated': None, 'content_type_id': 8, 'container_id': None, 'state_id': None, 'weight': None,
'effective': None, 'owner_id': None, 'expiration': None}] (Background on this error at: http://sqlalche.me/e/gkpj)
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment