Skip to content

Commit ee4328a

Browse files
committed
fix: use get_field_name_text function field name
1 parent bb02502 commit ee4328a

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

ormar/queryset/actions/order_action.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ def get_text_clause(self) -> sqlalchemy.sql.expression.TextClause:
9898
table_name = dialect.identifier_preparer.quote(table_name)
9999
field_name = dialect.identifier_preparer.quote(field_name)
100100

101-
return text(
102-
f"{prefix}{table_name}"
103-
f".{self._get_field_name_direction_nulls(field_name=field_name)}"
104-
)
101+
return text(f"{prefix}{table_name}.{self._get_field_direction_nulls()}")
105102

106103
def _split_value_into_parts(self, order_str: str) -> None:
107104
if order_str.startswith("-"):
@@ -111,37 +108,33 @@ def _split_value_into_parts(self, order_str: str) -> None:
111108
self.field_name = parts[-1]
112109
self.related_parts = parts[:-1]
113110

114-
def _generate_field_nulls_query(self, field_name: str, result: str) -> str:
111+
def _generate_field_nulls_query(self, result: str) -> str: # pragma: no cover
115112
"""
116113
Generate the Final Query with handling mysql syntax for nulls value
117114
118-
:param field_name: string name of this field for order
119-
:type field_name: str
120115
:param result: query generated in previous stage without nulls value
121116
:type result: str
122117
:return: result of the final query by field name and direction and nulls value
123118
:rtype: str
124119
"""
125120

126121
if not self.is_mysql_bool:
127-
return result + f" nulls {self.nulls}" # pragma: no cover
122+
return result + f" nulls {self.nulls}"
128123

129-
condition: str = "not" if self.nulls == "first" else "" # pragma: no cover
130-
return f"{field_name} is {condition} null, {result}" # pragma: no cover
124+
condition: str = "not" if self.nulls == "first" else ""
125+
return f"{self.get_field_name_text()} is {condition} null, {result}"
131126

132-
def _get_field_name_direction_nulls(self, field_name: str) -> str:
127+
def _get_field_direction_nulls(self) -> str:
133128
"""
134129
Generate the Query of Order for this field name by direction and nulls value
135130
136-
:param field_name: string name of this field for order
137-
:type field_name: str
138131
:return: result of the query by field name and direction and nulls value
139132
:rtype: str
140133
"""
141134

142-
result: str = f"{field_name} {self.direction}"
135+
result: str = f"{self.get_field_name_text()} {self.direction}"
143136
if self.nulls is not None:
144-
return self._generate_field_nulls_query(field_name=field_name, result=result)
137+
return self._generate_field_nulls_query(result=result)
145138

146139
return result
147140

0 commit comments

Comments
 (0)