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 get_loader returning None when load_jupyter_server_extension is not found (#1193)Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> #1193

Merged
merged 6 commits into from Feb 3, 2023

Conversation

cmd-ntrf
Copy link
Contributor

@cmd-ntrf cmd-ntrf commented Feb 1, 2023

Description

The function extension.utils.get_loader returns None instead of raising an exception when an extension does not define_load_jupyter_server_extension nor load_jupyter_server_extension.

Reproduce

  1. Install an extension that does not define load_jupyter_server_extension nor _load_jupyter_server_extension, for example jupyterlab-nvdashboard
  2. Launch jupyter lab
    The following exception appears in the log:
     Traceback (most recent call last):
      File "/opt/jupyterhub/lib64/python3.9/site-packages/jupyter_server/extension/manager.py", line 355, in load_extension
        extension.load_all_points(self.serverapp)
      File "/opt/jupyterhub/lib64/python3.9/site-packages/jupyter_server/extension/manager.py", line 229, in load_all_points
        return [self.load_point(point_name, serverapp) for point_name in self.extension_points]
      File "/opt/jupyterhub/lib64/python3.9/site-packages/jupyter_server/extension/manager.py", line 229, in <listcomp>
        return [self.load_point(point_name, serverapp) for point_name in self.extension_points]
      File "/opt/jupyterhub/lib64/python3.9/site-packages/jupyter_server/extension/manager.py", line 222, in load_point
        return point.load(serverapp)
      File "/opt/jupyterhub/lib64/python3.9/site-packages/jupyter_server/extension/manager.py", line 148, in load
        return loader(serverapp)
    TypeError: 'NoneType' object is not callable

Expected behavior

The user should get an AttributeError exception instead of a TypeError, making it clear that _load_jupyter_server_extension is missing for the extension being loaded.

Context

The problem was introduced by PR #742, when a default value of None was configured if gettattr could not find load_jupyter_server_extension. The change was made to satisfy Flake8.

Fix implemented in this PR

Remove the default value for gettatr in get_loader and set the comment # noqa B009 to keep Flake8 satisfied.

@welcome
Copy link

welcome bot commented Feb 1, 2023

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@codecov
Copy link

codecov bot commented Feb 1, 2023

Codecov Report

Base: 79.14% // Head: 80.41% // Increases project coverage by +1.27% 🎉

Coverage data is based on head (7fa7c57) compared to base (f3fe168).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1193      +/-   ##
==========================================
+ Coverage   79.14%   80.41%   +1.27%     
==========================================
  Files          68       68              
  Lines        8117     8119       +2     
  Branches     1584     1583       -1     
==========================================
+ Hits         6424     6529     +105     
+ Misses       1280     1175     -105     
- Partials      413      415       +2     
Impacted Files Coverage Δ
jupyter_server/extension/utils.py 97.87% <100.00%> (+8.98%) ⬆️
...ter_server/services/kernels/connection/channels.py 61.06% <0.00%> (-1.11%) ⬇️
jupyter_server/base/handlers.py 78.82% <0.00%> (+0.58%) ⬆️
jupyter_server/utils.py 85.46% <0.00%> (+5.81%) ⬆️
jupyter_server/serverapp.py 79.94% <0.00%> (+7.80%) ⬆️
jupyter_server/services/shutdown.py 100.00% <0.00%> (+23.07%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kevin-bates kevin-bates added the bug label Feb 2, 2023
@blink1073
Copy link
Collaborator

Thanks @cmd-ntrf! It looks like one test needs to be updated:

=========================== short test summary info ============================
FAILED tests/extension/test_utils.py::test_get_loader - AttributeError: 'object' object has no attribute 'load_jupyter_server_extension'

cmd-ntrf and others added 3 commits February 3, 2023 10:30
get_loader was never raising ExtensionLoadingError because it would
fallback to check if load_jupyter_server_extension is present and
if it was not, it would raise an AttributeError.
@cmd-ntrf
Copy link
Contributor Author

cmd-ntrf commented Feb 3, 2023

While fixing the tests, I realized get_loader would never raised ExtensionLoadingError, so I splitted the try/except in two. I have also added a test that a deprecated warning was raised, instead of ignoring the warning. Finally, the test for when the module is missing both possible function name now correctly validates that an ExtensionLoadingError is raised.

@blink1073
Copy link
Collaborator

The link failure is unrelated but the lint failure is: tests/extension/test_utils.py:2:8: F401 warnings imported but unused.

Copy link
Collaborator

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

Thank you!

@blink1073 blink1073 changed the title Fix get_loader returning None when load_jupyter_server_extension is not found Fix get_loader returning None when load_jupyter_server_extension is not found (#1193)Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Feb 3, 2023
@blink1073 blink1073 merged commit 89b35f4 into jupyter-server:main Feb 3, 2023
@welcome
Copy link

welcome bot commented Feb 3, 2023

Congrats on your first merged pull request in this project! 🎉
congrats
Thank you for contributing, we are very proud of you! ❤️

@cmd-ntrf
Copy link
Contributor Author

cmd-ntrf commented Feb 3, 2023

I originally stumbled on this issue while using jupyter-server 1.23.5, so this patch should probably be backported to 1.x.

@blink1073
Copy link
Collaborator

@meeseeksdev please backport to 1.x

@lumberbot-app
Copy link

lumberbot-app bot commented Feb 3, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 1.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 89b35f4640a49b0e8443476c9b09f4096deb42f6
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #1193: Fix get_loader returning None when load_jupyter_server_extension is not found (#1193)Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>'
  1. Push to a named branch:
git push YOURFORK 1.x:auto-backport-of-pr-1193-on-1.x
  1. Create a PR against branch 1.x, I would have named this PR:

"Backport PR #1193 on branch 1.x (Fix get_loader returning None when load_jupyter_server_extension is not found (#1193)Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

cmd-ntrf added a commit to cmd-ntrf/jupyter_server that referenced this pull request Feb 3, 2023
blink1073 added a commit that referenced this pull request Feb 3, 2023
…rver_extension is not found (#1193) (#1199)Co-authored-by: Steven Silvester <steven.silvester@ieee.org> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Backport #1193 to 1.x

* bump isort dep

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix check links job name

---------

Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants