internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: jupyterhub/jupyterhub

Issue:
Clearing spawn failure inside spawner 
**Describe the bug**

rsdockerspawner is a customer spawner that does automatic resource management. The only way I could figure out to return "no resources" was to [throw a 429](https://github.com/radiasoft/rsdockerspawner/blob/9fb308bddc255216aaa896b753b8d98dd2df670e/rsdockerspawner/rsdockerspawner.py#L464), but this is seen [as an error in user.py](https://github.com/jupyterhub/jupyterhub/blob/689a312756483db77b874115d829f93a9d6fb96b/jupyterhub/user.py#L616). 

There's no way to clear that error, which [ends up getting stored in base.py](https://github.com/jupyterhub/jupyterhub/blob/689a312756483db77b874115d829f93a9d6fb96b/jupyterhub/handlers/base.py#L835).

Also, the error message that is passed to `tornado.web.HTTPError` is not shown to the user, just the generic 429 Too Many Requests error.

While there is a link to the home page, it would be better to have a (big :) button that says "Try Again". People don't see the link.

**To Reproduce**

Login twice with different GitHub user names to http://alpha-jupyter.radiasoft.org. The garbage collector is set to a very short interval so it should produce the error.

**Expected behavior**

The spawner should be able to manage the resources in the spirit of [EAFP](https://en.wikipedia.org/wiki/EAFP). A 429 is a known exception for too few resources.

**Screenshots**
n/a

**Desktop (please complete the following information):**
n/a

**Additional context**
n/a



Discussion:

Resolving patch:
diff --git a/jupyterhub/handlers/pages.py b/jupyterhub/handlers/pages.py
--- a/jupyterhub/handlers/pages.py
+++ b/jupyterhub/handlers/pages.py
@@ -281,13 +281,20 @@ async def get(self, for_user, server_name=''):
             # Implicit spawn on /user/:name is not allowed if the user's last spawn failed.
             # We should point the user to Home if the most recent spawn failed.
             exc = spawner._spawn_future.exception()
-            self.log.error(
-                "Preventing implicit spawn for %s because last spawn failed: %s",
-                spawner._log_name,
-                exc,
+            self.log.error("Previous spawn for %s failed: %s", spawner._log_name, exc)
+            spawn_url = url_path_join(self.hub.base_url, "spawn", user.escaped_name)
+            self.set_status(500)
+            html = self.render_template(
+                "not_running.html",
+                user=user,
+                server_name=server_name,
+                spawn_url=spawn_url,
+                failed=True,
+                failed_message=getattr(exc, 'jupyterhub_message', ''),
+                exception=exc,
             )
-            # raise a copy because each time an Exception object is re-raised, its traceback grows
-            raise copy.copy(exc).with_traceback(exc.__traceback__)
+            self.finish(html)
+            return
 
         # Check for pending events. This should usually be the case
         # when we are on this page.


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
Releasing 1.0
With #2435 rounding out the final thing I think we need for the next release, I think it's time to put together the 1.0 release.

This should consist of:

- [x] assembling changelog #2440
- [x] making sure new features are well documented
- [x] publishing beta release
- [x] test beta (perhaps by adding it to the z2jh chart)
- [ ] release 1.0 final


Discussion:
1.0b1 is officially published.

Resolving patch:
diff --git a/jupyterhub/_version.py b/jupyterhub/_version.py
--- a/jupyterhub/_version.py
+++ b/jupyterhub/_version.py
@@ -6,7 +6,7 @@
     1,
     0,
     0,
-    "b2",  # release (b1, rc1, or "" for final or dev)
+    # "b2",  # release (b1, rc1, or "" for final or dev)
     # "dev",  # dev or nothing
 )
 


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
Login/Logout button does not update its label after logout
To reproduce from a running notebook:

1. Click on Logout button.
2. UI changes and displays the "Successfully logged out" message.

The righthand button does not update to "Login".

<img width="1206" alt="screenshot 2018-03-29 17 44 02" src="https://user-images.githubusercontent.com/2680980/38115182-28a72740-3379-11e8-9040-21d99a25cb7f.png">

3. Clicking on the button will cause it to update the label to "Login".

<img width="1216" alt="screenshot 2018-03-29 17 50 08" src="https://user-images.githubusercontent.com/2680980/38115357-acc0475a-3379-11e8-94fe-4a7420e519ce.png">



Discussion:

Resolving patch:
diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py
--- a/jupyterhub/handlers/base.py
+++ b/jupyterhub/handlers/base.py
@@ -484,6 +484,8 @@ def clear_login_cookie(self, name=None):
             path=url_path_join(self.base_url, 'services'),
             **kwargs
         )
+        # Reset _jupyterhub_user
+        self._jupyterhub_user = None
 
     def _set_cookie(self, key, value, encrypted=True, **overrides):
         """Setting any cookie should go through here


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
Link to hub given as HTTP and not HTTPS
Hi there,

While trying to configure JupyterHub locally, running in the terminal gives the following link:

"JupyterHub is now running at http://127.0.0.1:port/"

To which my browser responded "The connection was reset". I found that using HTTPS and ignoring the warnings solved this issue. 

My specs are: Ubuntu 19.04, Firefox and I used openssl to get a key and certificate.
JupyterHub version: 1.0.0

I believe it makes sense to change this to HTTPS for future users.


Discussion:
Can you share your configuration? It's possible that we should be updating bind_url if ssl configuration is detected.

Resolving patch:
diff --git a/jupyterhub/app.py b/jupyterhub/app.py
--- a/jupyterhub/app.py
+++ b/jupyterhub/app.py
@@ -576,6 +576,22 @@ def _url_part_changed(self, change):
         """,
     ).tag(config=True)
 
+    @validate('bind_url')
+    def _validate_bind_url(self, proposal):
+        """ensure protocol field of bind_url matches ssl"""
+        v = proposal['value']
+        proto, sep, rest = v.partition('://')
+        if self.ssl_cert and proto != 'https':
+            return 'https' + sep + rest
+        elif proto != 'http' and not self.ssl_cert:
+            return 'http' + sep + rest
+        return v
+
+    @default('bind_url')
+    def _bind_url_default(self):
+        proto = 'https' if self.ssl_cert else 'http'
+        return proto + '://:8000'
+
     subdomain_host = Unicode(
         '',
         help="""Run single-user servers on subdomains of this host.


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
Failed build of docs in CI
```
#!/bin/bash -eo pipefail
cd docs
make html
npm install && touch node_modules
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN jupyterhub-docs-build@0.8.0 No repository field.

added 216 packages from 514 contributors and audited 325 packages in 4.188s

14 packages are looking for funding
  run `npm fund` for details

found 2 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
npm run rest-api

> jupyterhub-docs-build@0.8.0 rest-api /home/circleci/project/docs
> bootprint openapi ./rest-api.yml source/_static/rest-api

[
  'source/_static/rest-api/index.html',
  'source/_static/rest-api/main.css',
  'source/_static/rest-api/main.css.map'
]
sphinx-build -b html -d build/doctrees  "-W" source build/html
Running Sphinx v2.4.4
Adding copy buttons to code blocks...
making output directory... done
/home/circleci/.local/lib/python3.6/site-packages/sphinx/util/compat.py:32: RemovedInSphinx30Warning: The config variable "source_parsers" is deprecated. Please update your extension for the parser and remove the setting.
  RemovedInSphinx30Warning)
/home/circleci/.local/lib/python3.6/site-packages/sphinx/util/compat.py:36: RemovedInSphinx30Warning: app.add_source_parser() does not support suffix argument. Use app.add_source_suffix() instead.
  app.add_source_parser(suffix, parser)

Theme error:
no theme named 'pandas_sphinx_theme' found (missing theme.conf?)
Makefile:64: recipe for target 'html' failed
make: *** [html] Error 2
```

FYI @choldgraf @betatim


Discussion:
Good catch, this is because we just made a (one time) name change to “pydata_sphinx_theme”. I will make a pr when I am back at a computer!
For inspiration/copy&pasting in repo2docker this PR fixed it https://github.com/jupyter/repo2docker/pull/864/

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -74,7 +74,7 @@ def setup(app):
 # -- Options for HTML output ----------------------------------------------
 
 # The theme to use for HTML and HTML Help pages.
-html_theme = 'pandas_sphinx_theme'
+html_theme = 'pydata_sphinx_theme'
 
 html_logo = '_static/images/logo/logo.png'
 html_favicon = '_static/images/logo/favicon.ico'


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
slow_spawn_timeout warning when timeout is disabled (0)

### Bug description

We're using zero-to-jupyterhub-k8s which sets `slow_spawn_timeout` to 0 [1] and that results in a warning in the hub logs, e.g.:

>Jul 23 14:09:36 hub-55d978d7cb-75lwl hub WARNING WARNING 2020-07-23T19:09:36.897Z [JupyterHub base:950] User hub-stress-test-123 is slow to start (timeout=0) 

If the `slow_spawn_timeout` is disabled we should not log a warning for that situation since we're not waiting at all.

Related to #1222 

[1] https://github.com/jupyterhub/zero-to-jupyterhub-k8s/commit/b4738edc5dd5a3b7ecc117ca34c556afbf8981e6

#### Expected behaviour
We shouldn't log a warning for an expected situation where we're not waiting.

#### Actual behaviour
Don't log a warning when `slow_spawn_timeout` is 0 and we don't wait for the server to start.

### How to reproduce
Configure `slow_spawn_timeout: 0` in `c.JupyterHub.tornado_settings`, create a user and start their server then check the hub logs for the warning.

### Your personal set up

 - OS: linux
 - Version: commit 8a3790b01ff944c453ffcc0486149e2a58ffabea
 - Configuration: zero-to-jupyterhub-k8s default configuration for `slow_spawn_timeout` (0 in this case)



Discussion:
@mriedem I love how easy it is to read up on related topics thanks to your very thorough writeups! :heart:
👍 You're too kind. 😃 

Resolving patch:
diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py
--- a/jupyterhub/handlers/base.py
+++ b/jupyterhub/handlers/base.py
@@ -977,13 +977,16 @@ def abort():
             # waiting_for_response indicates server process has started,
             # but is yet to become responsive.
             if spawner._spawn_pending and not spawner._waiting_for_response:
-                # still in Spawner.start, which is taking a long time
-                # we shouldn't poll while spawn is incomplete.
-                self.log.warning(
-                    "User %s is slow to start (timeout=%s)",
-                    user_server_name,
-                    self.slow_spawn_timeout,
-                )
+                # If slow_spawn_timeout is intentionally disabled then we
+                # don't need to log a warning, just return.
+                if self.slow_spawn_timeout > 0:
+                    # still in Spawner.start, which is taking a long time
+                    # we shouldn't poll while spawn is incomplete.
+                    self.log.warning(
+                        "User %s is slow to start (timeout=%s)",
+                        user_server_name,
+                        self.slow_spawn_timeout,
+                    )
                 return
 
             # start has finished, but the server hasn't come up


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
500 error does not output error description
### Bug description

Launching a single user notebook leads to a 500 error (as expected) if the user's server fails to authenticate with the JupyterHub. However, the error's description is not displayed due to an invalid key.

#### Expected behavior

Display the user error in the 500 error template page.

<img width="857" alt="500_error_with_message" src="https://user-images.githubusercontent.com/920170/90351983-e8051580-e00f-11ea-8ece-90c4cacd1e97.png">


#### Actual behaviour

Generic 500 error.

<img width="814" alt="500_error_without_message" src="https://user-images.githubusercontent.com/920170/90352007-fb17e580-e00f-11ea-8ed8-40a348194e6c.png">

Additionally, the logs display `TypeError: can only concatenate str (not "NoneType") to str` since the key/value does not exist (None).

### How to reproduce

Launch a single user notebook that has an unrecognized (invalid) client or token to get a `401` error.



Discussion:

Resolving patch:
diff --git a/jupyterhub/services/auth.py b/jupyterhub/services/auth.py
--- a/jupyterhub/services/auth.py
+++ b/jupyterhub/services/auth.py
@@ -371,9 +371,13 @@ def _api_request(self, method, url, **kwargs):
             )
             app_log.warning(r.text)
             msg = "Failed to check authorization"
-            # pass on error_description from oauth failure
+            # pass on error from oauth failure
             try:
-                description = r.json().get("error_description")
+                response = r.json()
+                # prefer more specific 'error_description', fallback to 'error'
+                description = response.get(
+                    "error_description", response.get("error", "Unknown error")
+                )
             except Exception:
                 pass
             else:


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
c.JupyterHub.services.*.api_token has a minimum length required?
### Bug description

When configuring a JupyterHub service with an api_token that is 7 characters (ddd4444) instead of 8 characters (dddd4444) or more, the JupyterHub responds with 403 when it otherwise don't.

I expected to get some warning or early error if it had a minimum length, rather than a runtime failure 403 response to REST API requests.

### How to reproduce

This was discovered in the JupyterHub Helm chart's CI system where making the dev-config.yaml specify `hub.services.test.apiToken=ddd4444` led to 403 errors accessing the REST api while it would work fine if set to an eight characters long token.

The JupyterHub configuration to reproduce without z2jh may be...

```python
c.JupyterHub.services = [
    {
        "name": test,
        "admin": true,
        "api_token": "ddd4444",
    }
]
```

And then sending a Rest API request with the oken.

### Setup

JupyterHub 1.3.0 was used in z2jh at this point in time.


Discussion:

Resolving patch:
diff --git a/jupyterhub/app.py b/jupyterhub/app.py
--- a/jupyterhub/app.py
+++ b/jupyterhub/app.py
@@ -1876,7 +1876,7 @@ async def _add_tokens(self, token_dict, kind):
                         # don't allow bad tokens to create users
                         db.delete(obj)
                         db.commit()
-                        raise
+                    raise
             else:
                 self.log.debug("Not duplicating token %s", orm_token)
         db.commit()


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
Unused variable standard_permissions in update_roles
This line of code seems pointless and makes my attempt to understand the code a bit harder. Should it be a comment or similar instead?

https://github.com/jupyterhub/jupyterhub/blob/b029d983f99878b365c28a6e8b606cfeb0e8d3d7/jupyterhub/roles.py#L464


Discussion:

Resolving patch:
diff --git a/jupyterhub/roles.py b/jupyterhub/roles.py
--- a/jupyterhub/roles.py
+++ b/jupyterhub/roles.py
@@ -440,31 +440,34 @@ def _token_allowed_role(db, token, role):
 
 
 def assign_default_roles(db, entity):
-    """Assigns default role to an entity:
+    """Assigns default role(s) to an entity:
     users and services get 'user' role, or admin role if they have admin flag
     tokens get 'token' role
     """
     if isinstance(entity, orm.Group):
         pass
     elif isinstance(entity, orm.APIToken):
-        app_log.debug('Assigning default roles to tokens')
+        app_log.debug('Assigning default role to token')
         default_token_role = orm.Role.find(db, 'token')
         if not entity.roles and (entity.user or entity.service) is not None:
             default_token_role.tokens.append(entity)
             app_log.info('Added role %s to token %s', default_token_role.name, entity)
-        db.commit()
+            db.commit()
     # users and services can have 'user' or 'admin' roles as default
     else:
         kind = type(entity).__name__
-        app_log.debug(f'Assigning default roles to {kind} {entity.name}')
+        app_log.debug(f'Assigning default role to {kind} {entity.name}')
         _switch_default_role(db, entity, entity.admin)
 
 
 def update_roles(db, entity, roles):
-    """Updates object's roles checking for requested permissions
-    if object is orm.APIToken
+    """Add roles to an entity (token, user, etc.)
+
+    If it is an API token, check role permissions against token owner
+    prior to assignment to avoid permission expansion.
+
+    Otherwise, it just calls `grant_role` for each role.
     """
-    standard_permissions = {'inherit', 'read:inherit'}
     for rolename in roles:
         if isinstance(entity, orm.APIToken):
             role = orm.Role.find(db, rolename)
@@ -477,12 +480,11 @@ def update_roles(db, entity, roles):
                     app_log.info('Adding role %s to token: %s', role.name, entity)
                 else:
                     raise ValueError(
-                        f'Requested token role {rolename} of {entity} has more permissions than the token owner'
+                        f'Requested token role {rolename} for {entity} has more permissions than the token owner'
                     )
             else:
                 raise KeyError(f'Role {rolename} does not exist')
         else:
-            app_log.debug('Assigning default roles to %s', type(entity).__name__)
             grant_role(db, entity=entity, rolename=rolename)
 
 


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
Jupyterhub logout TypeError with xsrf_cookie_kwargs
Jupyterhub version 2.1.1

If xsrf_cookie_kwargs (example below) are configured on Jupyterhub tornado_settings, the request to clear_cookie() in base.py clear_login_cookie during logout can result in the following error:

TypeError: clear_cookie() got an unexpected keyword argument 'Secure'

Example configuration:

```python
c.JupyterHub.tornado_settings = {
    'xsrf_cookie_kwargs': {
        'Secure': True
    }
  }
```

It appears appears that the logout handler attempts to pass in all kwargs to web.py clear_cookies() method for the _xsrf cookie, which accepts only name, path and domain as parameters.

https://github.com/jupyterhub/jupyterhub/blob/c23cddeb515dbcc0bc59c063ddba32d191624dcb/jupyterhub/handlers/base.py#L532




Discussion:
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
<br>If you haven't done so already, check out [Jupyter's Code of Conduct](https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md). Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
![welcome](https://raw.githubusercontent.com/jupyterhub/.github/master/images/welcome.jpg)
You can meet the other [Jovyans](https://jupyter.readthedocs.io/en/latest/community/content-community.html?highlight=jovyan#what-is-a-jovyan) by joining our [Discourse forum](http://discourse.jupyter.org/). There is also an intro thread there where you can stop by and say Hi! :wave:
<br>Welcome to the Jupyter community! :tada:


Resolving patch:
diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py
--- a/jupyterhub/handlers/base.py
+++ b/jupyterhub/handlers/base.py
@@ -526,10 +526,16 @@ def clear_login_cookie(self, name=None):
             path=url_path_join(self.base_url, 'services'),
             **kwargs,
         )
-        # clear tornado cookie
+        # clear_cookie only accepts a subset of set_cookie's kwargs
+        clear_xsrf_cookie_kwargs = {
+            key: value
+            for key, value in self.settings.get('xsrf_cookie_kwargs', {})
+            if key in {"path", "domain"}
+        }
+
         self.clear_cookie(
             '_xsrf',
-            **self.settings.get('xsrf_cookie_kwargs', {}),
+            **clear_xsrf_cookie_kwargs,
         )
         # Reset _jupyterhub_user
         self._jupyterhub_user = None


Test patch:
Repository: jupyterhub/jupyterhub

Issue:
Spawner should stop on failed auth_state_hook
<!-- Thank you for contributing. These HTML commments will not render in the issue, but you can delete them once you've read them if you prefer! -->

### Bug description
When a custom `auth_state_hook` is implemented for a spawner, and when the hook is executed, if an exception is raised, then spawning should stop. Currently if an exception is raised, it is logged, ignored, and the spawning continues. It seems to be due to [this part of the code](https://github.com/jupyterhub/jupyterhub/blob/b11c02c6e01531702e99d60317d5691999a0a4a6/jupyterhub/spawner.py#L1021)

#### Expected behaviour
Spawning should stop if the `auth_state_hook` raises an exception.

#### Actual behaviour
The spawning continues.

### How to reproduce
``` python
def my_auth_state_hook(spawner, auth_state):
    raise Exception()
```
Then in config set:
``` python
spawner.auth_state_hook = my_auth_state_hook
```

### Your personal set up

 - OS:
Linux
 - Version:
1.1.0



Discussion:
@rcthomas You added the original code in https://github.com/jupyterhub/jupyterhub/pull/2555

What are your thoughts on erroring instead of ignoring Exceptions in `run_auth_state_hook`?
The pre-spawn hook errors instead of ignores, so changing this to match sounds good to me.

Resolving patch:
diff --git a/jupyterhub/spawner.py b/jupyterhub/spawner.py
--- a/jupyterhub/spawner.py
+++ b/jupyterhub/spawner.py
@@ -1142,10 +1142,7 @@ def run_post_stop_hook(self):
     async def run_auth_state_hook(self, auth_state):
         """Run the auth_state_hook if defined"""
         if self.auth_state_hook is not None:
-            try:
-                await maybe_future(self.auth_state_hook(self, auth_state))
-            except Exception:
-                self.log.exception("auth_state_hook failed with exception: %s", self)
+            await maybe_future(self.auth_state_hook(self, auth_state))
 
     @property
     def _progress_url(self):


Test patch: