From 1ed4e29a94782b998030b0577ec4322e8af5d000 Mon Sep 17 00:00:00 2001 From: Quinten Steenhuis Date: Mon, 13 May 2024 11:30:11 -0400 Subject: [PATCH] Try potential fix for #850 --- docassemble/AssemblyLine/sessions.py | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/docassemble/AssemblyLine/sessions.py b/docassemble/AssemblyLine/sessions.py index 5b136656..b86556dd 100644 --- a/docassemble/AssemblyLine/sessions.py +++ b/docassemble/AssemblyLine/sessions.py @@ -11,6 +11,7 @@ DALazyTemplate, DAList, DAObject, + DAGlobal, DASet, format_time, get_config, @@ -23,6 +24,7 @@ set_parts, set_session_variables, set_variables, + SQLObject, url_action, url_ask, user_has_privilege, @@ -62,6 +64,7 @@ "get_saved_interview_list", "interview_list_html", "is_file_like", + "is_unsafe_to_store", "is_valid_json", "load_interview_answers", "load_interview_json", @@ -244,7 +247,6 @@ def is_file_like(obj: Any) -> bool: ALStaticDocument, ALExhibit, ALExhibitList, - DALazyTemplate, ), ): return True @@ -252,6 +254,26 @@ def is_file_like(obj: Any) -> bool: return False +def is_unsafe_to_store(obj: Any) -> bool: + """ + Return True if the object is unsafe to store and retreive from a session. + + Most objects are safe to store and retrieve from a session, but we currently screen out: + + - File-like objects, e.g., DAFile and Assembly Line variants for attachments + - DALazyTemplate + - SQLObject objects + - DAGlobal objects + + Args: + obj (Any): The object to test + + Returns: + bool: True if the object is unsafe to store in a session. + """ + return is_file_like(obj) or isinstance(obj, (DAGlobal, SQLObject, DALazyTemplate)) + + def set_interview_metadata( filename: str, session_id: int, data: Dict, metadata_key_name="metadata" ) -> None: @@ -1113,7 +1135,7 @@ def get_filtered_session_variables( key, value = items_to_check.pop() # This condition only will apply to "top level" variables - if is_file_like(value): + if is_unsafe_to_store(value): del all_vars[key] continue @@ -1125,7 +1147,7 @@ def get_filtered_session_variables( ) # skip over properties etc. vs using object.dir() for attr in attr_list: attr_val = object.__getattribute__(value, attr) - if is_file_like(attr_val): + if is_unsafe_to_store(attr_val): delattr(value, attr) elif isinstance(attr_val, (DAList, DASet, DAObject)): items_to_check.append( @@ -1135,7 +1157,7 @@ def get_filtered_session_variables( if isinstance(value, (DAList, DASet)): new_elements = [] for subitem in value.elements: - if not is_file_like(subitem): + if not is_unsafe_to_store(subitem): new_elements.append(subitem) if isinstance(subitem, (DAList, DASet, DAObject)): items_to_check.append((None, subitem))