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

Silencing of TypeErrors during value retrieval #453

Open
dferens opened this issue Jun 23, 2023 · 0 comments
Open

Silencing of TypeErrors during value retrieval #453

dferens opened this issue Jun 23, 2023 · 0 comments

Comments

@dferens
Copy link

dferens commented Jun 23, 2023

Hi,

At my company we've run into issues when TypeError exceptions were silenced inside django-elasticsearch-dsl.

When ES field is targeting model's @property and TypeError is raised within getter, it will be completely hidden as int(attr) will raise ValueError and None will be returned:

try:
instance = getattr(instance, attr)
except ObjectDoesNotExist:
return None
except (TypeError, AttributeError):
try:
instance = instance[int(attr)]
except (
IndexError, ValueError,
KeyError, TypeError
):
if self._required:
raise VariableLookupError(
"Failed lookup for key [{}] in "
"{!r}".format(attr, instance)
)
return None

We need to remove that TypeError from except clause and figure out an alternative solution. At my company, we've been struggling with this for a while so I can prepare a PR if you agree on this.

Thanks!

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

1 participant