kennethreitz / records

SQL for Humans™
https://pypi.python.org/pypi/records/
ISC License
7.16k stars 574 forks source link

TypeError: 'default' is an invalid keyword argument for this function #123

Open minibear0523 opened 6 years ago

minibear0523 commented 6 years ago

Does anyone know why this error happened? Even if the dataset doesn't contains the date format.

timofurrer commented 6 years ago

What version of tablib are you using?

minibear0523 commented 6 years ago

My tablib version is '0.12.1'

lucag commented 6 years ago

Hi, I'm seeing the same also, on at least:

The following code (in a file x.py)

import records

db  = records.Database('mysql://127.0.0.1:3306/fn2b?user=*&password=*')
lus = db.query('select * from LexUnit')

for i, lu in enumerate(lus):
    if i < 10:
        print(lu)
    else:
        break

Fails as follows:

Traceback (most recent call last):
  File "x.py", line 12, in <module>
    print(lu)
  File "/usr/local/lib/python3.6/site-packages/records.py", line 45, in __repr__
    return '<Record {}>'.format(self.export('json')[1:-1])
  File "/usr/local/lib/python3.6/site-packages/records.py", line 96, in export
    return self.dataset.export(format, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/tablib/core.py", line 467, in export
    return export_set(self, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/tablib/formats/_json.py", line 30, in export_set
    return json.dumps(dataset.dict, default=date_handler)
TypeError: 'default' is an invalid keyword argument for this function

On both machines,

$ pip3 list | grep tablib                                                      
tablib                            0.12.1

Should I go ahead and modify tablib to remove the offending keyword? Anything else?

Cheers, —L.

lucag commented 6 years ago

It's because ujson.dumps, which is tentatively imported by tablib/formats/_json.py, does not support the default keyword. And I think it doesn't support any, for that matter.

vlcinsky commented 6 years ago

Is there any json library, which is likely to run without failing? May be we could add such library into records requirements (or force the standard one) to ensure, dumping into JSON format works more stable.

raulmonge commented 6 years ago

Hi, same error here

Windows 10 (version 1709, SO compilation 16299.371), Python 3.6.4

The following code (in a file fill_keywords_table.py)

import records

db  = records.Database('mysql://root:123456@localhost/keyword_tracking')
rows = db.query('select * from keywords ')
print(rows.all())

Fail Trace

Traceback (most recent call last):
  File "fill_keywords_table.py", line 24, in <module>
    main()
  File "fill_keywords_table.py", line 21, in main
    fill.fillDatabaseWithKeywords()
  File "fill_keywords_table.py", line 12, in fillDatabaseWithKeywords
    print(check_keyword.all())
  File "C:\Python36-32\lib\site-packages\records.py", line 45, in __repr__
    return '<Record {}>'.format(self.export('json')[1:-1])
  File "C:\Python36-32\lib\site-packages\records.py", line 96, in export
    return self.dataset.export(format, **kwargs)
  File "C:\Python36-32\lib\site-packages\tablib\core.py", line 467, in export
    return export_set(self, **kwargs)
  File "C:\Python36-32\lib\site-packages\tablib\formats\_json.py", line 30, in export_set
    return json.dumps(dataset.dict, default=date_handler)
TypeError: 'default' is an invalid keyword argument for this function

Tablib Version

tablib 0.12.1

I can handle the query results in dict format but not like default (json?)

import records

db  = records.Database('mysql://root:123456@localhost/keyword_tracking')
rows = db.query('select * from keywords ')
print(rows.all(as_dict=True))
vlcinsky commented 6 years ago

Do you have ujson installed?

tablib seems to be the cause and relevant issue https://github.com/kennethreitz/tablib/issues/297 is already filed (and fixed), but not released yet).

raulmonge commented 6 years ago

Yes I have installed ujson too.

Ujson version

ujson 1.35

vlcinsky commented 6 years ago

@raulmonge the https://github.com/kennethreitz/tablib/issues/297 describes the cause and has workaround (patching json lib in tablib.format.json).

Either use that trick or uninstall ujson and it shall work.

vlcinsky commented 6 years ago

This issue will have to be fixed in tablib probably.