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: several disabled pylint rules in models/helpers.py #10909

Merged
merged 7 commits into from
Sep 18, 2020

Conversation

kkucharc
Copy link
Contributor

SUMMARY

Fixed several disabled pylint rules in models/helpers.py:

  • pylint import list seems not conflicting with isort anymore
  • changed escaping of [ to double backslash
  • changed private method which is used as public
  • defined more specific exception handling in JSON loading
  • removed unnecessary error handling and replaced with condition

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

superset/models/helpers.py Outdated Show resolved Hide resolved
@kkucharc kkucharc changed the title Fixed several disabled pylint rules in models/helpers.py [WIP] Fixed several disabled pylint rules in models/helpers.py Sep 16, 2020
@kkucharc kkucharc changed the title [WIP] Fixed several disabled pylint rules in models/helpers.py Fixed several disabled pylint rules in models/helpers.py Sep 16, 2020
@kkucharc kkucharc changed the title Fixed several disabled pylint rules in models/helpers.py fix: several disabled pylint rules in models/helpers.py Sep 16, 2020
@kkucharc
Copy link
Contributor Author

@willbarrett Would you find a time to take a look?

Copy link
Member

@willbarrett willbarrett left a comment

Choose a reason for hiding this comment

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

LGTM after rebase.

superset/models/helpers.py Outdated Show resolved Hide resolved
@kkucharc
Copy link
Contributor Author

@willbarrett Thanks for review.
I just rebased it.

except Exception: # pylint: disable=broad-except
except (TypeError, JSONDecodeError) as exc:
logger.error(
"Unable to load an extra json: %r. Leaving empty.", exc, exc_info=True
Copy link
Member

Choose a reason for hiding this comment

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

Can exc or exc_info log data from self.extra_json ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I will add it to an exception logger.

Copy link
Member

Choose a reason for hiding this comment

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

maybe I did not explain myself right, sorry. I want to make sure that self.extra_json never gets logged by TypeError or JSONDecodeError by exc or exc_info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dpgaspar do you mind to take a look again? I have one doubt: do you think is it possible there could be raised exception while accessing self.extra_json for logger?

Copy link
Contributor Author

@kkucharc kkucharc Sep 18, 2020

Choose a reason for hiding this comment

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

Och, I see, then I just did the opposite thing! :) Reverting this change.
To be honest I think JSONDecodeError will show error message %s: line %d column %d (char %d).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be sure I check that and any of them won't show what self.extra_json contains.
JSONDecodeError should something like:
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 11 (char 10)
with stacktrace.
And TypeError something like this for example:
TypeError: the JSON object must be str, bytes or bytearray, not dict

Copy link
Member

Choose a reason for hiding this comment

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

nice then, thks

@@ -321,11 +322,11 @@ def template_params_dict(self) -> Dict[Any, Any]:
return json_to_dict(self.template_params) # type: ignore


def _user_link(user: User) -> Union[Markup, str]: # pylint: disable=no-self-use
if not user:
def _user_link(_user: User) -> Union[Markup, str]:
Copy link
Member

Choose a reason for hiding this comment

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

Can't we just remove the # pylint: disable=no-self-use on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are absolutely right! Somehow I had to mistake that for unused-argument. Thanks! I'm changing it right-away.

Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

left a couple of comments

- removed unecesary function's param rename
- added extra JSON content in exception
@dpgaspar dpgaspar merged commit 2003442 into apache:master Sep 18, 2020
@kkucharc kkucharc deleted the lint_audit_models_helpers branch September 25, 2020 07:32
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
* Removed conflicting lint and isort check in model helpers seems it's not appearing anymore

* Removed disabled linting for accessing private method. `parent_foreign_key_mappings` becomes public because it is accessed by other instance than `self`.

* Updated model's helper - removed unecessary exception and replaced with check while accessing global context to reset ownerships.

* Updated model's helper - renamed unused attribute to private in user link method.

* Updated model's helper - added specific exception for adding extra json column. Removed disabled pylint rule.

* Applied changes after review to `models/helpers.py`:
- removed unecesary function's param rename
- added extra JSON content in exception

* Removed self.extra_json content from exception message.
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.38.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 0.38.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants