Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django TimeField gives 'datetime.time' object has no attribute 'microseconds' when querying its model's 'sa' attribute #43

Closed
tackler opened this issue Feb 1, 2017 · 3 comments
Labels

Comments

@tackler
Copy link

tackler commented Feb 1, 2017

Steps to reproduce

  1. Python 2.7.6, pip==9.0.1, Django==1.10.5, MySQL-python==1.2.5, aldjemy==0.6.0
  2. Create a model with TimeField
  3. Do necessary migrations
  4. Create an object of the models using django's "objects.create()". You can give either a string or a datetime.time or datetime.datetime instance for the field.
  5. Create a session using aldjemy.core.get_engine()
  6. session.query(<model name>.sa).all() or <model name>.sa.query().all() gives the error
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "~/.virtualenvs/test/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2638, in all
    return list(self)
  File "~/.virtualenvs/test/local/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 90, in instances
    util.raise_from_cause(err)
  File "~/.virtualenvs/test/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 "~/.virtualenvs/test/local/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 75, in instances
    rows = [proc(row) for row in fetch]
  File "~/.virtualenvs/test/local/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 437, in _instance
    loaded_instance, populate_existing, populators)
  File "~/.virtualenvs/test/local/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 498, in _populate_full
    dict_[key] = getter(row)
  File "~/.virtualenvs/test/local/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/types.py", line 413, in process
    microseconds = value.microseconds
AttributeError: 'datetime.time' object has no attribute 'microseconds'
@tackler
Copy link
Author

tackler commented Feb 1, 2017

This is possibly because Django stores MySQL's time as datetime.time overriding MySQLdb's way of saving as datetime.timedelta which is being given to SQLA. Since, SQLA is expecting only datetime.timedelta (all the mysql-python connector packages give datetime.timedelta), we are getting the above error.

@ryanhiebert
Copy link
Member

Wow, that's quite interesting behavior. @tackler, do you have a suggestion on how we could address this, or is it best to leave it to user code? I tend to feel that making either Django or SQLAlchemy work differently than they were designed is unwise.

@stale
Copy link

stale bot commented May 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 25, 2020
@stale stale bot closed this as completed Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants