question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] TypeError at library import (Python 3.9.1)

See original GitHub issue

Describe the bug I’m new to Python/FastAPI, so it is very well possible that it’s just me doing something wrong, but my code fails to compile as soon as I add the line to import either SingleTenantAzureAuthorizationCodeBearer or MultiTenantAzureAuthorizationCodeBearer and I’m getting this error: TypeError: unhashable type: ‘list’

First I thought it’s related to my already written code, so I’ve started a clean project and followed the tutorial in the documentation, but that also fails as soon as I add the import line. So I’m completely lost here.

I’m using Python 3.9.1 and FastAPI 0.74.1

To Reproduce Add code line: from fastapi_azure_auth import SingleTenantAzureAuthorizationCodeBearer

Stack trace

Traceback (most recent call last):
  File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\program files\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\...\AppData\Roaming\Python\Python39\Scripts\uvicorn.exe\__main__.py", line 7, in <module>
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\click\core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\click\core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\click\core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\uvicorn\main.py", line 435, in main
    run(app, **kwargs)
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\uvicorn\main.py", line 461, in run
    server.run()
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\uvicorn\server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "c:\program files\python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "c:\program files\python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\uvicorn\server.py", line 67, in serve
    config.load()
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\uvicorn\config.py", line 458, in load
    self.loaded_app = import_from_string(self.app)
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\uvicorn\importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
  File "c:\program files\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File ".\main.py", line 7, in <module>
    from fastapi_azure_auth import SingleTenantAzureAuthorizationCodeBearer
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\fastapi_azure_auth\__init__.py", line 1, in <module>
    from fastapi_azure_auth.auth import (  # noqa: F401
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\fastapi_azure_auth\auth.py", line 20, in <module>
    class AzureAuthorizationCodeBearerBase(SecurityBase):
  File "C:\Users\...\AppData\Roaming\Python\Python39\site-packages\fastapi_azure_auth\auth.py", line 29, in AzureAuthorizationCodeBearerBase
    iss_callable: Optional[Callable[[str], Awaitable[str]]] = None,
  File "c:\program files\python39\lib\typing.py", line 262, in inner
    return func(*args, **kwds)
  File "c:\program files\python39\lib\typing.py", line 339, in __getitem__
    return self._getitem(self, parameters)
  File "c:\program files\python39\lib\typing.py", line 463, in Optional
    return Union[arg, type(None)]
  File "c:\program files\python39\lib\typing.py", line 262, in inner
    return func(*args, **kwds)
  File "c:\program files\python39\lib\typing.py", line 339, in __getitem__
    return self._getitem(self, parameters)
  File "c:\program files\python39\lib\typing.py", line 451, in Union
    parameters = _remove_dups_flatten(parameters)
  File "c:\program files\python39\lib\typing.py", line 231, in _remove_dups_flatten
    return tuple(_deduplicate(params))
  File "c:\program files\python39\lib\typing.py", line 205, in _deduplicate
    all_params = set(params)
TypeError: unhashable type: 'list'

Your configuration Exactly the same as the tutorial here: https://intility.github.io/fastapi-azure-auth/single-tenant/fastapi_configuration

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
JonasKscommented, Mar 2, 2022

Well, I’d say that’s a even better reason to make an attempt!

I’ll write the steps here, if you want to try it out (and become a contributor), you’ll have the opportunity now. These steps are the same for basically all open source projects. I’ll be happy to answer any questions you might have! If you don’t have time or don’t want to, just let me know and I’ll do it. 😊

Fork

First off, you need to fork the project. You do this by clicking this button:

image

You then go into your project, which should now exist under your own profile here.

Clone

Clone this project, either using https or ssh. If you haven’t set up SSH keys, you chose https.

image

Copy this URL, and paste it in your terminal in the folder you’d like it to clone to:

git clone <url>

Example:
image

OR with ssh:

image

(Cloning projects can also be done through clients or editors, but I can’t help you with that)

Install the project dependencies

Now, we have the project installed. If you have poetry, you can just type poetry install and it’ll install the entire environment:

image

If you don’t have poetry, you must install it first. There’s the official way here, but if you’re on a mac you can also just do a brew install poetry. pip install poetry should also work in most cases.

When you’ve written poetry install you can write poetry shell to activate the environment:

image

Pre-commit

This project uses pre-commit. It’s not really documented anywhere, so I’ll make sure to do that! How ever, all it requires is that you run pre-commit install. This will install the pre-commit hooks: image

Changing branch and edit the code

Now, all we have to do is create a new branch (from the branch you’re on) and edit the code:

git checkout -b fix/typing-error
image

And then, edit our code in your editor.

Now, we can write git status to see what files we’ve made changes to:

image

We then add this file to commit, by typing git add <filename>, or git add . to add them all. When you’ve added the file, you can create a commit. git commit -m "<commit message>" is the simplest way:

image

As you can see, the pre-commit hooks are now installing.

Making pre-commit hooks pass

With my changes, the pre-commit hook actually changed my file, and my commit did not go through: image

Typing git status I can see that the file is changed from last time I add it:

image

Since the file was fixed, all I need to do is to add the file and try to commit again:

image

Success!

Pushing and creating a pull request

Now we push these changes into our branch by typing git push origin <branch name>:

image

Then, navigate back to this repository in the web browser and you’ll see this button. Click it and create a pull request.

image

When you create the pull request, tests will automatically run in the branch. 😊

0reactions
JonasKscommented, Mar 7, 2022

@ravaszf , I’ve pushed a change to PyPi.

Thank you for your bug report and contribution! Let me know if there’s anything more I can help you with.

EDIT: You’ve also been tagged as a contributor if you look at the release here. We also appreciate a ⭐ on the project if you haven’t done so 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's New In Python 3.9 — Python 3.11.1 documentation
Aliases to Abstract Base Classes in the collections module, like collections. ... no longer masked by TypeError in the in operator and functions...
Read more >
[BUG] TypedDict defined failed on module initialization ...
TypeError raised when defining a TypedDict inheritance in Ubuntu Python 3.9. This error is displayed at runtime import instead of compile time.
Read more >
Getting a TypeError: unhashable type: 'list' when import flet ...
A am runing on windows Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, ... this is the first import for the library to be used...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
Bug :1523 - "[IDEA] Offload work by distributing trivial ebuild maintenance to ... Bug:111388 - "pyfest ebuild-- python module for festival" status:RESOLVED ...
Read more >
libpython3.9: _collections_abc.py :type 'types.GenericAlias' is ...
Report forwarded to debian-bugs-dist@lists.debian.org, ... Python error: init_import_site: Failed to import the site module Python runtime ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found