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

Fix NoneType AttributeError in firefox extension plugin #713

Merged
merged 4 commits into from
Jul 18, 2024
Merged

Fix NoneType AttributeError in firefox extension plugin #713

merged 4 commits into from
Jul 18, 2024

Conversation

M1ra1B0T
Copy link
Contributor

This PR fixes a NoneType AttributeError in the firefox extension plugin.
When parsing the firefox extension information from the json file, we use the dictionary get method to access the relevant key value pairs. However, I ran into an uncatched NoneType AttributeError if the original key value is None, but we expect a nested dictionary, e.g. for the "name" field.

Additionally, the error message was slightly adapted, so instead of logging the whole user object, it now only prints the username as it should.

@Schamper
Copy link
Member

Do you have some test data or could you add some data to the unit test for this? Maybe I'm missing something but on first glance the previous code should be functionality identical?

In [1]: extension = {}

In [2]: repr(extension.get("defaultLocale", {}).get("name"))
Out[2]: 'None'

In [3]: extension = {"defaultLocale": {}}

In [4]: repr(extension.get("defaultLocale", {}).get("name"))
Out[4]: 'None'

@M1ra1B0T
Copy link
Contributor Author

M1ra1B0T commented Jul 15, 2024

@Schamper The error occurs if the field defaultLocale is actually None or null

>>> extension = {"defaultLocale": None}
>>> repr(extension.get("defaultLocale", {}).get("name"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'get'

Copy link

codecov bot commented Jul 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.05%. Comparing base (f999b3a) to head (40fee57).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #713   +/-   ##
=======================================
  Coverage   75.05%   75.05%           
=======================================
  Files         295      295           
  Lines       25084    25084           
=======================================
  Hits        18827    18827           
  Misses       6257     6257           
Flag Coverage Δ
unittests 75.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Schamper Schamper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested something a bit more concise.

@Schamper Schamper merged commit b754587 into fox-it:main Jul 18, 2024
17 of 18 checks passed
@Schamper
Copy link
Member

Thanks! Was actually running into this issue too while working on another feature.

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

Successfully merging this pull request may close these issues.

2 participants