From 1c77d3150c908fc30f9581ee6761c5521fa8f378 Mon Sep 17 00:00:00 2001 From: alec_dev Date: Thu, 16 Jan 2025 10:52:16 -0600 Subject: [PATCH 1/6] add one-to-one rel type to objformat logic --- specifyweb/stored_queries/queryfieldspec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specifyweb/stored_queries/queryfieldspec.py b/specifyweb/stored_queries/queryfieldspec.py index 2d80d8aeb61..feab5828fc4 100644 --- a/specifyweb/stored_queries/queryfieldspec.py +++ b/specifyweb/stored_queries/queryfieldspec.py @@ -255,7 +255,7 @@ def add_spec_to_query(self, query, formatter=None, aggregator=None, cycle_detect if self.is_relationship(): # will be formatting or aggregating related objects - if self.get_field().type == 'many-to-one': + if self.get_field().type in {'many-to-one', 'one-to-one'}: query, orm_model, table, field = self.build_join(query, self.join_path) query, orm_field = query.objectformatter.objformat(query, orm_model, formatter, cycle_detector) else: From 4837bfb21efac9b40b2d774310770280c77ab34c Mon Sep 17 00:00:00 2001 From: alec_dev Date: Thu, 16 Jan 2025 14:41:37 -0600 Subject: [PATCH 2/6] add temp blank_nulls catalognumber conditional --- specifyweb/stored_queries/blank_nulls.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/specifyweb/stored_queries/blank_nulls.py b/specifyweb/stored_queries/blank_nulls.py index 48aa2195936..4443e211a25 100644 --- a/specifyweb/stored_queries/blank_nulls.py +++ b/specifyweb/stored_queries/blank_nulls.py @@ -1,3 +1,4 @@ +import re from sqlalchemy.sql import expression from sqlalchemy.ext.compiler import compiles from sqlalchemy.types import String @@ -38,5 +39,8 @@ def _blank_nulls(element: blank_nulls, compiler: MySQLCompiler_mysqldb, **kwargs expr = compiler.process(element.clauses.clauses[0]) if isinstance(element.clauses.clauses[0], blank_nulls): return expr + elif re.search(r'CAST.+\`CatalogNumber\`\sAS\sDECIMAL.+', expr) is not None: + # NOTE: Temporary expiriment, this fixes CatalogNumber casting to DECIMAL instead of string + return "IFNULL(%s, NULL)" % expr else: return "IFNULL(%s, '')" % expr From 9b8ccc866362736427560ef6f726304992a81198 Mon Sep 17 00:00:00 2001 From: alec_dev Date: Thu, 16 Jan 2025 14:43:43 -0600 Subject: [PATCH 3/6] simplify blank_nulls conditional --- specifyweb/stored_queries/blank_nulls.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specifyweb/stored_queries/blank_nulls.py b/specifyweb/stored_queries/blank_nulls.py index 4443e211a25..98cf1e6a1be 100644 --- a/specifyweb/stored_queries/blank_nulls.py +++ b/specifyweb/stored_queries/blank_nulls.py @@ -41,6 +41,7 @@ def _blank_nulls(element: blank_nulls, compiler: MySQLCompiler_mysqldb, **kwargs return expr elif re.search(r'CAST.+\`CatalogNumber\`\sAS\sDECIMAL.+', expr) is not None: # NOTE: Temporary expiriment, this fixes CatalogNumber casting to DECIMAL instead of string - return "IFNULL(%s, NULL)" % expr + # return "IFNULL(%s, NULL)" % expr + return expr else: return "IFNULL(%s, '')" % expr From 147301bbebb693d79606418517afff445d9e3270 Mon Sep 17 00:00:00 2001 From: alec_dev Date: Thu, 16 Jan 2025 17:00:57 -0600 Subject: [PATCH 4/6] null dataobjformatter logger --- specifyweb/stored_queries/blank_nulls.py | 4 ++-- specifyweb/stored_queries/format.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/specifyweb/stored_queries/blank_nulls.py b/specifyweb/stored_queries/blank_nulls.py index 98cf1e6a1be..01e6f4ab743 100644 --- a/specifyweb/stored_queries/blank_nulls.py +++ b/specifyweb/stored_queries/blank_nulls.py @@ -41,7 +41,7 @@ def _blank_nulls(element: blank_nulls, compiler: MySQLCompiler_mysqldb, **kwargs return expr elif re.search(r'CAST.+\`CatalogNumber\`\sAS\sDECIMAL.+', expr) is not None: # NOTE: Temporary expiriment, this fixes CatalogNumber casting to DECIMAL instead of string - # return "IFNULL(%s, NULL)" % expr - return expr + # return expr + return "IFNULL(%s, NULL)" % expr else: return "IFNULL(%s, '')" % expr diff --git a/specifyweb/stored_queries/format.py b/specifyweb/stored_queries/format.py index 034da95faa2..436385f286f 100644 --- a/specifyweb/stored_queries/format.py +++ b/specifyweb/stored_queries/format.py @@ -98,7 +98,12 @@ def getFormatterFromSchema() -> Element: if result is not None: return result - return lookup('class', specify_model.classname) + result = lookup('class', specify_model.classname) + if result is not None: + return result + + logger.warning("no dataobjformatter for %s", specify_model.classname) + return None def hasFormatterDef(self, specify_model: Table, formatter_name) -> bool: if formatter_name is None: From 87df266c05138d5a69603c1edf5ccc3f89a4e6af Mon Sep 17 00:00:00 2001 From: alec_dev Date: Fri, 17 Jan 2025 14:40:31 -0600 Subject: [PATCH 5/6] rescope PR --- specifyweb/stored_queries/blank_nulls.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/specifyweb/stored_queries/blank_nulls.py b/specifyweb/stored_queries/blank_nulls.py index 01e6f4ab743..48aa2195936 100644 --- a/specifyweb/stored_queries/blank_nulls.py +++ b/specifyweb/stored_queries/blank_nulls.py @@ -1,4 +1,3 @@ -import re from sqlalchemy.sql import expression from sqlalchemy.ext.compiler import compiles from sqlalchemy.types import String @@ -39,9 +38,5 @@ def _blank_nulls(element: blank_nulls, compiler: MySQLCompiler_mysqldb, **kwargs expr = compiler.process(element.clauses.clauses[0]) if isinstance(element.clauses.clauses[0], blank_nulls): return expr - elif re.search(r'CAST.+\`CatalogNumber\`\sAS\sDECIMAL.+', expr) is not None: - # NOTE: Temporary expiriment, this fixes CatalogNumber casting to DECIMAL instead of string - # return expr - return "IFNULL(%s, NULL)" % expr else: return "IFNULL(%s, '')" % expr From f3fc2f71ded8564e7c6f85b2fcc76993d0e5169d Mon Sep 17 00:00:00 2001 From: alec_dev Date: Fri, 17 Jan 2025 14:41:24 -0600 Subject: [PATCH 6/6] sql log reformatting --- specifyweb/specify/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specifyweb/specify/utils.py b/specifyweb/specify/utils.py index b0b2f93a070..ccc4b7508f8 100644 --- a/specifyweb/specify/utils.py +++ b/specifyweb/specify/utils.py @@ -38,7 +38,7 @@ def log_sqlalchemy_query(query): # Call this function to debug the raw SQL query generated by SQLAlchemy from sqlalchemy.dialects import mysql compiled_query = query.statement.compile(dialect=mysql.dialect(), compile_kwargs={"literal_binds": True}) - raw_sql = str(compiled_query) + raw_sql = str(compiled_query).replace('\n', ' ') + ';' logger.debug(raw_sql) # Run in the storred_queries.execute file, in the execute function, right before the return statement, line 546 # from specifyweb.specify.utils import log_sqlalchemy_query; log_sqlalchemy_query(query)