gothinkster / flask-realworld-example-app

Exemplary real world JSON API built with Flask (Python)
https://realworld.io/
MIT License
902 stars 309 forks source link

TypeError: can't compare offset-naive and offset-aware datetimes #6

Closed nikhilkul closed 7 years ago

nikhilkul commented 7 years ago

I get this error when I update the user profile using angular-realworld-example-app

realazizk commented 7 years ago

hello @nikhilkul I'm not sure why but I can't reproduce the problem, either ways can paste the error traceback ?

nikhilkul commented 7 years ago

Sure. Here you go.

127.0.0.1 - - [26/Jul/2017 16:18:49] "PUT /api/user HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask_jwt/__init__.py", line 177, in decorator
    return fn(*args, **kwargs)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask_apispec/annotations.py", line 115, in wrapped
    return wrapper(*args, **kwargs)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask_apispec/wrapper.py", line 23, in __call__
    response = self.call_view(*args, **kwargs)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/flask_apispec/wrapper.py", line 39, in call_view
    return self.func(*args, **kwargs)
  File "/Users/github/gitdir/flask-realworld-example-app/conduit/user/views.py", line 61, in update_user
    user.update(**kwargs)
  File "/Users/github/gitdir/flask-realworld-example-app/conduit/extensions.py", line 25, in update
    return commit and self.save() or self
  File "/Users/github/gitdir/flask-realworld-example-app/conduit/extensions.py", line 31, in save
    db.session.commit()
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py", line 157, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 874, in commit
    self.transaction.commit()
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 461, in commit
    self._prepare_impl()
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 441, in _prepare_impl
    self.session.flush()
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2139, in flush
    self._flush(objects)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2259, in _flush
    transaction.rollback(_capture_exception=True)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2223, in _flush
    flush_context.execute()
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 389, in execute
    rec.execute(self)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 548, in execute
    uow
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 177, in save_obj
    mapper, table, update)
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 659, in _emit_update_statements
    lambda rec: (
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 485, in _collect_update_commands
    value, state.committed_state[propkey]) is not True:
  File "/Users/github/.virtualenvs/spinn/lib/python2.7/site-packages/sqlalchemy/sql/type_api.py", line 359, in compare_values
    return x == y
TypeError: can't compare offset-naive and offset-aware datetimes
realazizk commented 7 years ago

sorry my bad I didn't test with python2, 5ffc9e693c5f89759bc15e8cc8528922082fb511 fixes it, just rerun your migrations because I actually added the updatedAt column now.

(if the migration fails run

$ rm -fr migrations/ && rm dev.db && flask db init && flask db migrate && flask db upgrade

thanks for bearing with me.