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

Bug when second list is empty #10

Open
KKomarov opened this issue Mar 29, 2017 · 3 comments
Open

Bug when second list is empty #10

KKomarov opened this issue Mar 29, 2017 · 3 comments

Comments

@KKomarov
Copy link

KKomarov commented Mar 29, 2017

Kind of a bug:

>>> import jsondiff
>>> a = []
>>> b = ['a', 'b', 'c']
>>> jsondiff.diff(a,b)
['a', 'b', 'c']  # ok
>>> jsondiff.diff(b,a)
[]  # wrong. expected: {delete: [3, 2, 1]}
>>> jsondiff.diff(b,a, syntax='explicit')
[]  # wrong. expected: {delete: [3, 2, 1]}
>>> jsondiff.diff(a,b, syntax='symmetric')
[[], ['a', 'b', 'c']]  # ok ?
@ericremoreynolds
Copy link
Contributor

Hello @KKomarov,

Please check out #4 for some insight into this behaviour. In this case, jsondiff considers the two lists to be completely different therefore represents the difference as a substitution rather than a patch. It is perhaps debatable whether this is the best default behaviour in the explicit case, but it's a design choice not a bug.

Hope this helps.

@KKomarov
Copy link
Author

KKomarov commented Apr 3, 2017

@ericremoreynolds Thank you, I agree there is no problem with symmetric syntax. But others syntaxes have problems.

# another example
>>> from jsondiff import diff
>>> diff(['a', 'b', 'c'], ['a', 'c'])
{delete: [1]}
>>> diff(['a', 'b', 'c'], ['a'])
{delete: [2, 1]}
>>> diff(['a', 'b', 'c'], [])  # bug is here
[]

@dodysw
Copy link

dodysw commented Jan 28, 2018

Adding to this, jsondiff unexpectedly returned a list when one of the comparitor is an empty dict.

>>> jsondiff.diff({'a': 30},{},syntax='symmetric')
[{'a': 30}, {}]
>>> jsondiff.diff({},{'a': 20},syntax='symmetric')
[{}, {'a': 20}]

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

3 participants