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

Two test failures when ujson installed #262

Closed
jayvdb opened this issue May 11, 2019 · 8 comments
Closed

Two test failures when ujson installed #262

jayvdb opened this issue May 11, 2019 · 8 comments

Comments

@jayvdb
Copy link

jayvdb commented May 11, 2019

When ujson is installed, there are two errors in the test suite.

[   51s] =================================== FAILURES ===================================
[   51s] _______________________________ test_json_kwargs _______________________________
[   51s] 
[   51s] tmpdir = local('/tmp/pytest-of-abuild/pytest-0/test_json_kwargs0')
[   51s] 
[   51s]     def test_json_kwargs(tmpdir):
[   51s]         db_file = tmpdir.join('test.db')
[   51s] >       db = TinyDB(str(db_file), sort_keys=True, indent=4, separators=(',', ': '))
[   51s] 
[   51s] tests/test_storages.py:35: 
[   51s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   51s] tinydb/database.py:165: in __init__
[   51s]     self._table = self.table(default_table)
[   51s] tinydb/database.py:196: in table
[   51s]     table = table_class(self._cls_storage_proxy(self._storage, name), name, **options)
[   51s] tinydb/database.py:302: in __init__
[   51s]     data = self._read()
[   51s] tinydb/database.py:409: in _read
[   51s]     return self._storage.read()
[   51s] tinydb/database.py:96: in read
[   51s]     self._storage.write(raw_data)
[   51s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   51s] 
[   51s] self = <tinydb.storages.JSONStorage object at 0x7f661e42b910>
[   51s] data = {'_default': {}}
[   51s] 
[   51s]     def write(self, data):
[   51s]         self._handle.seek(0)
[   51s] >       serialized = json.dumps(data, **self.kwargs)
[   51s] E       TypeError: 'separators' is an invalid keyword argument for this function
[   51s] 
[   51s] tinydb/storages.py:112: TypeError
[   51s] ___________________________ test_insert_invalid_dict ___________________________
[   51s] 
[   51s] tmpdir = local('/tmp/pytest-of-abuild/pytest-0/test_insert_invalid_dict0')
[   51s] 
[   51s]     def test_insert_invalid_dict(tmpdir):
[   51s]         path = str(tmpdir.join('db.json'))
[   51s]     
[   51s]         with TinyDB(path) as _db:
[   51s]             data = [{'int': 1}, {'int': 2}]
[   51s]             _db.insert_multiple(data)
[   51s]     
[   51s]             with pytest.raises(TypeError):
[   51s] >               _db.insert({'int': {'bark'}})  # Fails
[   51s] E               Failed: DID NOT RAISE <type 'exceptions.TypeError'>
[   51s] 

Builds at https://build.opensuse.org/package/show/home:jayvdb:py-new/python-tinydb

@msiemens
Copy link
Owner

I've now fixed this by skipping these tests when ujson is installed. Honestly, it seems like ujson is pretty much unmaintained, so I'm thinking about maybe not recommending its use any more. I've created an issue for discussing this at #263.

@jayvdb
Copy link
Author

jayvdb commented Jun 19, 2019

The problem has not been solved by 4e6f849

If ujson is installed, using tinydb as documented breaks. i.e. use of separators etc in the constructor.

"Deprecating" it is not nice. The user isnt explicitly trying to use it with tinydb. They may need it for another part of their stack. It is merely available in their site-packages, and tinydb assumes it should use it, and fails.

@msiemens
Copy link
Owner

msiemens commented Jul 3, 2019

"Deprecating" it is not nice. The user isnt explicitly trying to use it with tinydb. They may need it for another part of their stack. It is merely available in their site-packages, and tinydb assumes it should use it, and fails.

You're right that I was a little quick to add a deprecation warning. I think it wasn't the best idea to add this auto-detection mechanism in the first place. Maybe it would be better to raise a warning that the behavior of JSONStorage may change if ujson is installed. We could also add an environment variable that disables automatic ujson usage so it's possible to run the test suite without errors even if ujson is installed.

In the long term I think we'd need to release a breaking release of TinyDB that removes ujson auto-import altogether.

@msiemens msiemens reopened this Jul 3, 2019
@stale
Copy link

stale bot commented Aug 2, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Feel free to reopen this if needed. Thank you for your contributions ❤️

@stale stale bot added the stale label Aug 2, 2019
@jayvdb
Copy link
Author

jayvdb commented Aug 2, 2019

Still an issue.

@stale stale bot removed the stale label Aug 2, 2019
@msiemens msiemens added the pinned label Aug 9, 2019
@msiemens
Copy link
Owner

This should be fixed with TinyDB v4 where ujson support has been dropped

@msiemens msiemens removed the pinned label Aug 12, 2020
@msiemens
Copy link
Owner

One still can write a custom storage that uses the ujson module but it won't be used automatically if found present

@jayvdb
Copy link
Author

jayvdb commented Aug 13, 2020

Thanks.

@jayvdb jayvdb closed this as completed Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants