mahmoud / glom

☄️ Python's nested data operator (and CLI), for all your declarative restructuring needs. Got data? Glom it! ☄️
https://glom.readthedocs.io
Other
1.89k stars 61 forks source link

v20.7 regression: PathAccessError `path` is a TType not a Path #185

Closed jakul closed 4 years ago

jakul commented 4 years ago

v20.7 has introduced a regression which can cause ex.path.values() to hang.

# In 20.5
In [1]: import glom
   ...: try:
   ...:      glom.glom({}, 'a')
   ...: except glom.PathAccessError as ex:
   ...:     print(ex.path.__class__)
   ...:
<class 'glom.core.Path'>

# In 20.7
In [1]:
   ...: import glom
   ...: try:
   ...:      glom.glom({}, 'a')
   ...: except glom.PathAccessError as ex:
   ...:     print(ex.path.__class__)
   ...:
<class 'glom.core.TType'>

Trying to call values() on a TType hangs indefinitely.

mahmoud commented 4 years ago

Hey @jakul! Thanks for the report. We made a lot of changes to exceptions in this latest release. Am I understanding correctly that you were relying on PathAccessError.path to be a instance of the Path type in order to use the Path.values() method?

If so, the direct workaround is to pass ex.path into Path and use the resulting object's .values() method.

   ...: import glom
   ...: try:
   ...:      glom.glom({}, 'a')
   ...: except glom.PathAccessError as ex:
   ...:     print(glom.Path(ex.path).values())

That'll give you ('a',) like in v20.5.0, and it's harmless to call Path on a path instance (like calling int(int(1))), so depending on where we land on this, it'll keep working.

jakul commented 4 years ago

PathAccessError.path to be a instance of the Path type in order to use the Path.values() method?

Yup, exactly that.

Thanks for the workaround. Are you planning to restore the previous behaviour - where path is always a Path instance - or leave .path as a TType permanently?

mahmoud commented 4 years ago

Discussed with @kurtbrose today and I think it makes sense to switch it back to a Path. Leaves more options open for API in the future. I'll be adding some tests to prevent this regression and cut another release tonight or tomorrow. Stay tuned!

jakul commented 4 years ago

Thanks @mahmoud, I appreciate it!