Skip to content

Commit

Permalink
Merge pull request #6094 from specify/issue-6053
Browse files Browse the repository at this point in the history
add one-to-one rel type to objformat logic
  • Loading branch information
acwhite211 authored Jan 17, 2025
2 parents 0873af2 + f3fc2f7 commit 36f7a7e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion specifyweb/specify/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion specifyweb/stored_queries/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/stored_queries/queryfieldspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 36f7a7e

Please sign in to comment.