Further information:
If I remove total_seconds() call, using whens={'SUCCESS': self.model.end_time
- self.model.start_time}, then I'll get the following error:
- File
"/usr/local/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py",
line *1038*, in get_list
query = query.all()
- File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line *2703*, in all
return list(self)
- File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/loading.py",
line *90*, in instances
util.raise_from_cause(err)
- File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py",
line *203*, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
- File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/loading.py",
line *78*, in instances
for row in fetch]
- File
"/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/sqltypes.py",
line *1717*, in process
return value - epoch
TypeError: unsupported operand type(s) for -: 'Decimal' and
'datetime.datetime'
On Monday, June 4, 2018 at 12:00:30 PM UTC-4, Hongqi Jia wrote:
>
> Here is how I define the query:
>
> _query = self.session.query(self.model.type,
> func.sum(case(value=self.model.final_status, whens={'SUCCESS':
> (self.model.end_time - self.model.start_time).total_seconds()}, else_=None)
>
>
> Here the end_time and start_time are columns of DateTime type.
>
>
> Here is the error I got. Desperately need help here, and really appreciate
> any suggestions!
>
>
> Error message:
>
>
>
>- File "/usr/local/lib/python2.7/site-packages/flask/app.py", line *1997*,
> in __call__
>
>return self.wsgi_app(environ, start_response)
>
>- File "/usr/local/lib/python2.7/site-packages/flask/app.py", line
>*1985*, in wsgi_app
>
>response = self.handle_exception(e)
>
>- File "/usr/local/lib/python2.7/site-packages/flask/app.py", line
>*1540*, in handle_exception
>
>reraise(exc_type, exc_value, tb)
>
>- File "/usr/local/lib/python2.7/site-packages/flask/app.py", line
>*1982*, in wsgi_app
>
>response = self.full_dispatch_request()
>
>- File "/usr/local/lib/python2.7/site-packages/flask/app.py", line
>*1614*, in full_dispatch_request
>
>rv = self.handle_user_exception(e)
>
>- File "/usr/local/lib/python2.7/site-packages/flask/app.py", line
>*1517*, in handle_user_exception
>
>reraise(exc_type, exc_value, tb)
>
>- File "/usr/local/lib/python2.7/site-packages/flask/app.py", line
>*1612*, in full_dispatch_request
>
>rv = self.dispatch_request()
>
>- File "/usr/local/lib/python2.7/site-packages/flask/app.py", line
>*1598*, in dispatch_request
>
>return self.view_functions[rule.endpoint](**req.view_args)
>
>- File "/usr/local/lib/python2.7/site-packages/flask_admin/base.py",
>line *69*, in inner
>
>return self._run_view(f, *args, **kwargs)
>
>- File "/usr/local/lib/python2.7/site-packages/flask_admin/base.py",
>line *368*, in _run_view
>
>return fn(self, *args, **kwargs)
>
>- File
>"/usr/local/lib/python2.7/site-packages/flask_admin/model/base.py",
>line *1882*, in index_view
>
>view_args.search, view_args.filters, page_size=page_size)
>
>- File
>"/usr/local/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py",
>line *997*, in get_list
>
>query = self.get_query()
>
>- File "/app/src/main/python/hermes_reporter/admin.py", line *344*, in
>get_query
>
>whens={'SUCCESS': (_model.updated_on - _model.created_on).total_seconds()},
>
>- File
>"/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py",
>line *682*, in __getattr__
>
>key)
>
>
> AttributeError: Neither 'BinaryExpression' object nor 'Comparator' object
> has an attribute 'total_seconds'
>
>
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.