ads icon indicating copy to clipboard operation
ads copied to clipboard

Fix bug in cached_property

Open timothygebhard opened this issue 2 years ago • 0 comments

I wanted to use ads to get the BibTeX code for a given set of papers, basically running[^1]:

import ads
papers = list(ads.query("^Casey, Andrew R."))
print(papers[1].bibtex)

However, that resulted in the following error:

Traceback (most recent call last):
  File "/Users/timothy/Desktop/ads/test.py", line 6, in <module>
    print(papers[1].bibtex)
  File "/Users/timothy/Desktop/ads/ads/utils.py", line 31, in __get__
    .format(self.func.__name__),
AttributeError: 'cached_property' object has no attribute 'func'

I started digging a bit into it, and I think the problem is the following: ads.utils.cached_property is supposed to be a very thin wrapper around werkzeug.utils.cached_property. However, the latter one was updated a while ago, and in particularly the constructor—on which the ads version relies—was changed (i.e., the func property was removed).

I have now adjusted the ads version of cached_property so that it matched the one in werkzeug again, which should fix the error above 🙂

[FYI, starting with Python 3.8, the built-in functools library comes with its own implementation of cached_property. Depending on which Python versions you want to support, that might be a way to drop the werkzeug dependency?]

[^1]: I have since come to realize that this is not the best approach, and that I should probably use ExportQuery() directly instead?

timothygebhard avatar Feb 14 '22 22:02 timothygebhard