dgilland / pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.
http://pydash.readthedocs.io
MIT License
1.32k stars 93 forks source link

get(queryset[0].field) on empty queryset fails on upgrade to pydash 6.0.0 #179

Closed AndyKilpatrick closed 1 year ago

AndyKilpatrick commented 1 year ago

Upgrade Django code to use pydash 6.0.0, I hit the following behaviour change. Not 100% sure if this was an intended change.

Code runs value = pydash.get(qs, "[0].field"), where qs is a Django queryset which may or may not be empty:

For pydash >=6.0.0 this fails with a call stack like this

.venv/lib/python3.9/site-packages/pydash/objects.py:528: in get my code.py: obj = base_get(obj, key, default=sentinel) .venv/lib/python3.9/site-packages/pydash/helpers.py:139: in base_get value = _base_get_object(obj, key, default=default) .venv/lib/python3.9/site-packages/pydash/helpers.py:181: in _base_get_object _raise_if_restricted_key(key)

I think (apologies if this is wrong) this may be a problem accessing "[0]" which was previously handled, returning None.

dgilland commented 1 year ago

Should be fixed in v6.0.1