|
21 | 21 | )
|
22 | 22 | from . import types
|
23 | 23 |
|
| 24 | +try: |
| 25 | + import arrow |
| 26 | +except ImportError: |
| 27 | + arrow = None |
| 28 | +try: |
| 29 | + from sqlalchemy_utils.types import ArrowType |
| 30 | +except ImportError: |
| 31 | + ArrowType = None |
| 32 | + |
24 | 33 |
|
25 | 34 | class UnrecognizedOperator(ValueError):
|
26 | 35 | pass
|
@@ -1071,6 +1080,14 @@ def __init__(self, sa_col, _now=None, default_op=None, default_value1=None,
|
1071 | 1080 | self._was_time_given1 = False
|
1072 | 1081 | self._was_time_given2 = False
|
1073 | 1082 |
|
| 1083 | + self.check_arrow_type() |
| 1084 | + |
| 1085 | + def check_arrow_type(self): |
| 1086 | + """Verify that the expression given to the filter is not ArrowType. If it |
| 1087 | + is, cast it to a date to avoid type problems in the date filter""" |
| 1088 | + if arrow and ArrowType and isinstance(self.sa_col.type, ArrowType): |
| 1089 | + self.sa_col = sa.sql.cast(self.sa_col, sa.Date) |
| 1090 | + |
1074 | 1091 | def set(self, op, value1, value2=None):
|
1075 | 1092 | super(DateFilter, self).set(op, value1, value2)
|
1076 | 1093 | self.format_display_vals()
|
@@ -1264,6 +1281,10 @@ def __init__(self, sa_col, _now=None, default_op=None, default_value1=None,
|
1264 | 1281 | default_value1=default_value1,
|
1265 | 1282 | default_value2=default_value2)
|
1266 | 1283 |
|
| 1284 | + def check_arrow_type(self): |
| 1285 | + """DateTimeFilter has no problems with ArrowType. Pass this case through.""" |
| 1286 | + pass |
| 1287 | + |
1267 | 1288 | def format_display_vals(self):
|
1268 | 1289 | ops_single_val = (
|
1269 | 1290 | ops.eq.key,
|
|
0 commit comments