strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Fix mypy false positives regarding to_pydantic

Open thejaminator opened this issue 1 year ago • 7 comments

Description

Closes #2015

Fixes false positives with the mypy plugin. Happened when to_pydantic was called on a type that was converted pydantic with all_fields=True.

Also fixes the type signature when to_pydantic is defined by the user.

from pydantic import BaseModel
from typing import Optional
import strawberry


class MyModel(BaseModel):
    email: str
    password: Optional[str]


@strawberry.experimental.pydantic.input(model=MyModel, all_fields=True)
class MyModelStrawberry:
    ...

MyModelStrawberry(email="").to_pydantic()
# previously would complain wrongly about missing email and password

Types of Changes

  • [ ] Core
  • [x] Bugfix
  • [ ] New feature
  • [ ] Enhancement/optimization
  • [ ] Documentation

Issues Fixed or Closed by This PR

Checklist

  • [ ] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have read the CONTRIBUTING document.
  • [ ] I have added tests to cover my changes.
  • [ ] I have tested the changes and verified that they work and don't break anything (as well as I can manage).

thejaminator avatar Jul 14 '22 10:07 thejaminator

/pre-release

thejaminator avatar Jul 14 '22 10:07 thejaminator

Codecov Report

Merging #2017 (c06ad42) into main (76ffc85) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #2017   +/-   ##
=======================================
  Coverage   98.02%   98.02%           
=======================================
  Files         144      144           
  Lines        5712     5712           
  Branches     1064     1064           
=======================================
  Hits         5599     5599           
  Misses         58       58           
  Partials       55       55           

codecov[bot] avatar Jul 14 '22 10:07 codecov[bot]

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Fixes false positives with the mypy plugin. Happened when to_pydantic was called on a type that was converted pydantic with all_fields=True.

Also fixes the type signature when to_pydantic is defined by the user.

from pydantic import BaseModel
from typing import Optional
import strawberry


class MyModel(BaseModel):
    email: str
    password: Optional[str]


@strawberry.experimental.pydantic.input(model=MyModel, all_fields=True)
class MyModelStrawberry:
    ...

MyModelStrawberry(email="").to_pydantic()
# previously would complain wrongly about missing email and password

Here's the preview release card for twitter:

Here's the tweet text:

🆕 Release (next) is out! Thanks to James Chua for the PR 👏

Get it here 👉 https://github.com/strawberry-graphql/strawberry/releases/tag/(next)

botberry avatar Jul 14 '22 10:07 botberry

/pre-release

thejaminator avatar Jul 14 '22 10:07 thejaminator

/pre-release

patrick91 avatar Jul 14 '22 10:07 patrick91

Pre-release

:wave:

Releasing commit [84602a7feae69fd8b51f0fc14bb974ad9b8672e3] to PyPi as pre-release! :package:

botberry avatar Jul 14 '22 10:07 botberry

Pre-release

:wave:

Pre-release 0.118.2.dev.1657794397 [84602a7feae69fd8b51f0fc14bb974ad9b8672e3] has been released on PyPi! :rocket: You can try it by doing:

poetry add strawberry-graphql==0.118.2.dev.1657794397

botberry avatar Jul 14 '22 10:07 botberry

Are there any blockers for getting this merged?

Skeen avatar Sep 20 '22 12:09 Skeen

@Skeen, I'll merge this now, thanks for you patience! If there's any other issue let us know, and thanks @thejaminator for the PR 😊

patrick91 avatar Sep 22 '22 14:09 patrick91