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

MongoDsn.build gives AttributeError #6945

Closed
1 task done
quizmoon opened this issue Jul 29, 2023 · 2 comments · Fixed by #7116
Closed
1 task done

MongoDsn.build gives AttributeError #6945

quizmoon opened this issue Jul 29, 2023 · 2 comments · Fixed by #7116
Assignees
Labels
bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable

Comments

@quizmoon
Copy link

quizmoon commented Jul 29, 2023

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Using build on MongoDsn gives error:

url = MongoDsn.build(scheme=scheme, username=username, password=password, host=host)
      ^^^^^^^^^^^^^^

File "/usr/lib/python3.11/typing.py", line 1287, in getattr
return getattr(self.origin, attr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/typing.py", line 450, in getattr
raise AttributeError(item)
AttributeError: build

Example Code

url = MongoDsn.build(scheme=scheme, username=username, password=password, host=host)

Python, Pydantic & OS Version

pydantic version: 2.1.1
        pydantic-core version: 2.4.0
          pydantic-core build: profile=release pgo=true mimalloc=true
               python version: 3.11.4 (main, Jun  7 2023, 12:45:48) [GCC 11.3.0]
                     platform: Linux-5.19.0-50-generic-x86_64-with-glibc2.35
     optional deps. installed: ['typing-extensions']

Selected Assignee: @hramezani

@quizmoon quizmoon added bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable labels Jul 29, 2023
@quizmoon
Copy link
Author

Additionally, if build url using MultiHostUrl and then create instance of MongoDsn from it:

url = MultiHostUrl.build(scheme=scheme, username=username, password=password, host=host)
MongoDsn(url)

Will give the error:

MongoDsn(url)
^^^^^^^^^^^^^
File "/usr/lib/python3.11/typing.py", line 1261, in call
result = self.origin(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/typing.py", line 462, in call
raise TypeError(f"Cannot instantiate {self!r}")
TypeError: Cannot instantiate typing.Union

@Kludex Kludex assigned Kludex and unassigned hramezani Jul 30, 2023
@Kludex
Copy link
Member

Kludex commented Jul 30, 2023

It doesn't look like you are in the latest version of Pydantic 🤔

You sure you are using the version 2.1.1?

Caused by #6827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants