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

Common mistakes docs section #8380

Closed
sydney-runkle opened this issue Dec 15, 2023 · 14 comments
Closed

Common mistakes docs section #8380

sydney-runkle opened this issue Dec 15, 2023 · 14 comments

Comments

@sydney-runkle
Copy link
Member

Many of the issues we get are repeats of the same common questions / mistakes. We should create a small docs section logging said common mistakes and their solutions :).

@SohamG934
Copy link

Hello, I would like to work on this issue!

@sydney-runkle
Copy link
Member Author

@SohamG934,

Great! Feel free to submit a PR and I'll review. A few common mistakes I can think of:

I'm sure there are many more that we could include - you could search on duplicate tags to see what issues have been reported the most frequently!

@SohamG934
Copy link

SohamG934 commented Dec 16, 2023 via email

@sydney-runkle
Copy link
Member Author

Hi @SohamG934,

I think we should create a new page for our documentation site that has various examples of common mistakes and ways to correct said mistakes. I don't see a reason to reference issues for the most part. You can create a fork of the pydantic repo and submit a PR with your changes 👍

@bL34cHig0
Copy link
Contributor

Hi @SohamG934,

I think we should create a new page for our documentation site that has various examples of common mistakes and ways to correct said mistakes. I don't see a reason to reference issues for the most part. You can create a fork of the pydantic repo and submit a PR with your changes 👍

Hi @sydney-runkle, is @SohamG934 still working on this issue?

If not, I'd like to work on it. Thank you

@sydney-runkle
Copy link
Member Author

@bL34cHig0,

I haven't seen a PR yet, so feel free to get started on this :). Thanks!

@sydney-runkle sydney-runkle assigned bL34cHig0 and unassigned SohamG934 Jan 26, 2024
@sydney-runkle
Copy link
Member Author

@bL34cHig0,

I've assigned you to this issue :)

@bL34cHig0
Copy link
Contributor

@sydney-runkle

Thank you for assigning me this issue. Just a couple questions:

  • Under which section of the docs, do you want the page to be added?
  • Is there a template I can use?

@sydney-runkle
Copy link
Member Author

@bL34cHig0,

There's no template at the moment - I'd recommend combing through issues listed as duplicates to see what kind of issues come up often.
Could you please add this section to the examples section on a new page for now? Thanks!

@bL34cHig0
Copy link
Contributor

@sydney-runkle

I have started working on documenting the common mistakes / questions. So I wanted to ask if I am on the right track.

Please see screenshot below. Thanks :)

image

Work done so far:

  • Created a new branch called common-mistakes-doc
  • Created a new page titled common_mistakes.md under the examples section.
  • Wrote the first common question / mistake.

Please kindly review it and let me know if this structure is okay or not. Thanks again

@sydney-runkle
Copy link
Member Author

@bL34cHig0,

The structure looks great. Nice work so far!

@sydney-runkle
Copy link
Member Author

Here's another I think should be included: #8708

@sydney-runkle
Copy link
Member Author

See #8759 (comment) as the reason for closing this issue. I think this collection is more helpful to have as an issue than as an official docs page, despite my initial motivations for filing this issue.

A helpful collection of recommendations, thanks to @bL34cHig0: #8759

@sydney-runkle
Copy link
Member Author

sydney-runkle commented Feb 29, 2024

Below shows the relevant docs sections for explaining each of these questions:

How to implement custom error messages?

https://docs.pydantic.dev/latest/errors/errors/#customize-error-messages

Cannot use v1 model as type parameter in v2 generic model

https://docs.pydantic.dev/latest/migration/#changes-to-pydanticgenericsgenericmodel

AnyUrl adds trailing slash (/) in URL validation

https://docs.pydantic.dev/latest/migration/#url-and-dsn-types-in-pydanticnetworks-no-longer-inherit-from-str
See updates here: #7186

TypeError occurs when using Pydantic's Constraint Types

This one makes more sense to have reported + documented as an issue, which is explained well here:

This error occurs if you are using Python 3.9.7. To prevent this, upgrade to Python 3.9.8 or higher as there is a
bug in version 3.9.7. Also, it is discouraged to use some of the
con functions because they will be deprecated
in Pydantic 3.0. So check out the Discouraged warning for alternative solution.

validate_call decorator raises "AttributeError" when applied to an instance method of a class with __slots__

No longer an issue

Two validators consecutively do not report all errors

Pydantic does not currently support exhaustive validation, so it stops after the first error on a given field and
reports that validation error. Relevant feature request, for tracking: #7476

Can not use ValidationError __init__ method

https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core.ValidationError provides info on helpful static methods

Pydantic does not allow Literal enum value discriminator to be initialized by string

A simple solution to this is to allow your class to inherit from both str and Enum. This is the one case where I do think we could use a docs update in the relevant section of the docs :).

https://docs.pydantic.dev/latest/api/standard_library_types/#enum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants