Skip to content

Commit

Permalink
[field] Use cast in where representation to handle user-defined domains.
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-m committed Nov 22, 2024
1 parent 2942b9e commit 188e06b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions half_orm/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ def _where_repr(self, query, ho_id):
where_repr = ''
comp_str = '%s'
comp = self._comp()
cast = ''
if self.__value != NULL:
cast = f'::{self.__sql_type}'
if not self.unaccent:
where_repr = f"{self.__praf(query, ho_id)} {comp} {comp_str}"
where_repr = f"{self.__praf(query, ho_id)} {comp} {comp_str}{cast}"
else:
where_repr = f"unaccent({self.__praf(query, ho_id)}) {comp} unaccent({comp_str})"
where_repr = f"unaccent({self.__praf(query, ho_id)}) {comp} unaccent({comp_str}{cast})"
return where_repr

@property
Expand Down
2 changes: 1 addition & 1 deletion test/field/misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_comps(self):
self.post.content.set({'bonjour', 'au revoir'})
self.assertIsInstance(self.post.content.value, tuple)
self.post.content.unaccent = True
self.assertEqual(self.post.content._where_repr('', id(self.post)), 'unaccent("content") = unaccent(%s)')
self.assertEqual(self.post.content._where_repr('', id(self.post)), 'unaccent("content") = unaccent(%s::text)')

def test_py_type(self):
self.assertEqual(str(self.comment.tags.py_type), 'typing.List[str]')

0 comments on commit 188e06b

Please sign in to comment.