0

I have an ORM query as follows

results = db.session.query(MyData).filter(MyData.last_updated_date_time.between(from_date, to_date)).all()

passing parameters for from date is 2020-12-14 04:00:00 and for to date is 2020-12-15 04:00:00 and last_updated_date_time holds values 2020-12-09 03:08:22.301+00 , 2020-12-14 01:26:30.737+00 all are valid date time objects

This query works fine for some occasions and throws error stating

MyData.last_updated_date_time.between(from_date, to_date)
AttributeError: 'datetime.datetime' object has no attribute 'between'
ERROR:root:Error creating query 'datetime.datetime' object has no attribute 'between'

What can be the issue for this error?

not 0x12
  • 19,360
  • 22
  • 67
  • 133
  • 1
    It's been awhile since I used SqlAlchemy, but shouldn't that be:`filter(between(MyData.last_updated_date_time, from_date, to_date))`? – Adrian Klaver Dec 14 '20 at 22:04
  • hi @AdrianKlaver can use between for datetime column as per the code – not 0x12 Dec 14 '20 at 22:16
  • 1
    Then somewhere `MyData.last_updated_date_time` is not the `Column last_updated_date_time` but the value of `last_updated_date_time`. This from the error message `'datetime.datetime' object has no attribute 'between'`. You are trying to run `between` on a `datetime` not a `Column`. We will have to see what happens before the above to get a better answer. – Adrian Klaver Dec 14 '20 at 22:26
  • @AdrianKlaver Its referring to the column and I have followed the following https://stackoverflow.com/a/53158540/1004875 – not 0x12 Dec 16 '20 at 20:40
  • The error says it is not. You need to resolve that. We can help if you show the code that leads up the query you posted. – Adrian Klaver Dec 16 '20 at 20:47

0 Answers0