Skip to content

Commit 2441f46

Browse files
Parent instance <Article at …> is not bound to a Session; deferred load operation of attribute 'document_id' cannot proceed (Background on this error at: http://sqlalche.me/e/14/bhk3)
This is a workaround as I was unable to fix it in another way (either through `sqlalchemy.orm.undefer` or eager.
1 parent 62ed9da commit 2441f46

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

c2corg_api/views/document_info.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,20 @@ def _load_document_info(self, document_id, lang, clazz):
8989
filter(getattr(clazz, 'document_id') == document_id). \
9090
options(joinedload(locales_type_eager).
9191
load_only(*locales_load_only))
92+
9293
document_query = add_load_for_profiles(document_query, clazz)
9394
document = document_query.first()
9495

9596
if not document:
9697
raise HTTPNotFound('document not found')
9798

99+
if document.document_id:
100+
# TODO: find a better way than this workaround which calls
101+
# `document_id` before `set_best_locale` expunge the object
102+
# leading in: sqlalchemy.orm.exc.DetachedInstanceError:
103+
# Parent instance <Article at ...> is not bound to a Session;
104+
# deferred load operation of attribute 'document_id' cannot proceed
105+
pass
98106
set_best_locale([document], lang)
99107

100108
if document.redirects_to:

0 commit comments

Comments
 (0)