wmjie / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

ibm_db_sa datetime.datetime #90

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Fetch the ibm_db_sa branch
2. Build it
3. use it

Everything goes well (Connection, table reflection, ...) until I try to 
manipulate a column which is a date.

I use 
Python 2.7.2+ (default, Aug 16 2011, 07:03:08) 
[GCC 4.6.1] on linux2

Traceback (most recent call last):
  File "ibm_db_sa_check.py", line 51, in <module>
    cde = rs[i]
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 1672, in __getitem__
    return list(self[item:item+1])[0]
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 1667, in __getitem__
    return list(res)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 1960, in instances
    rows = [process[0](row, None) for row in fetch]
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 2600, in _instance
    populate_state(state, dict_, row, isnew, only_load_props)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 2454, in populate_state
    populator(state, dict_, row)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/strategies.py", line 150, in new_execute
    dict_[key] = row[col]
  File "/usr/local/lib/python2.7/dist-packages/ibm_db_sa-0.2.1-py2.7.egg/ibm_db_sa/base.py", line 289, in process
    if isinstance(value, datetime.datetime):
NameError: global name 'datetime' is not defined

I made some tests : 
And in this version :
>>> from datetime import *
>>> n = datetime.now()
>>> isinstance(n,datetime.datetime)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
>>> isinstance(n,datetime)
True

Why base.py use datetime.datetime as name for instance check ?
How to get this thing working ?
Regards

Original issue reported on code.google.com by julien.c...@gmail.com on 16 Nov 2011 at 2:47

GoogleCodeExporter commented 9 years ago
You have imported "from datetime import *" due to this datetime is equivalent 
to datetime.datetime

modify your script as follows 
===
>>> import datetime
>>> n = datetime.datetime.now()
>>> isinstance(n,datetime.datetime)
===

For SQLAlchemy issue Jaimy will get back to you.

Original comment by rahul.pr...@in.ibm.com on 17 Nov 2011 at 7:17

GoogleCodeExporter commented 9 years ago
Thanks rahul for this import lesson ;) (I'm yet a young pythonner)

By the way, the definition problem still exists and i can't stand the Jaimy 
feedback :)
Are you or Jaimy ever available on IRC ?

Regards

Original comment by julien.c...@gmail.com on 17 Nov 2011 at 9:05

GoogleCodeExporter commented 9 years ago
For temporary solution you can try with adding a import statement(import 
datetime) at the top in 
"/usr/local/lib/python2.7/dist-packages/ibm_db_sa-0.2.1-py2.7.egg/ibm_db_sa/base
.py" file.

I don't know why Jaimy has missed this statement(may be by mistake or 
intentionally ).

Original comment by rahul.pr...@in.ibm.com on 17 Nov 2011 at 11:03

GoogleCodeExporter commented 9 years ago
I did remove some unused modules from import list, apparently it was 
accidentally removed. however, this has been fixed in r153.

Original comment by jazlee on 18 Nov 2011 at 1:37