Title: Invalid name generation when using python reserved keywords by QuentinN42 · Pull Request #89 · sqlc-dev/sqlc-gen-python · GitHub
Open Graph Title: Invalid name generation when using python reserved keywords by QuentinN42 · Pull Request #89 · sqlc-dev/sqlc-gen-python
X Title: Invalid name generation when using python reserved keywords by QuentinN42 · Pull Request #89 · sqlc-dev/sqlc-gen-python
Description: Fixes #88 To fix this issue, here is my proposition: class Author(pydantic.BaseModel): + model_config = pydantic.ConfigDict( + validate_by_alias=True, + validate_by_name=True, + ) id: int + class_: str = pydantic.Field( + alias="class", + ) - class: str I'm replacing the class reserved keyword by class_. I add validate_by_name to allow us to define the class using Author(class_=...). I add validate_by_alias to allow JSON serde. Changes overview I've created a new file : internal/poet/reserved.go to append _ to reserved names. I've modified internal/gen.go::pydanticNode to add model_config = pydantic.ConfigDict I've modified internal/gen.go::fieldNode: If not reserved keyword, code unchanged. Else if using pydantic, add the _ and add pydantic.Field(...) Else if dataclasses, only add the _ Added tests Questions / possible issues To run the tests, I just clonned the repo and ran make test is it correct ? I had to update all comment from sqlc v1.28.0 to sqlc v1.29.0 is this intended ? The wasm sha256 changed, should I commit that ? In internal/poet/reserved.go I hardcoded reservedKeywords we should double check it and check if we want to keep it like that. Do you want me to add more tests ?
Open Graph Description: Fixes #88 To fix this issue, here is my proposition: class Author(pydantic.BaseModel): + model_config = pydantic.ConfigDict( + validate_by_alias=True, + validate_by_name=True, + ...
X Description: Fixes #88 To fix this issue, here is my proposition: class Author(pydantic.BaseModel): + model_config = pydantic.ConfigDict( + validate_by_alias=True, + validate_by_name=True, + ...
Opengraph URL: https://github.com/sqlc-dev/sqlc-gen-python/pull/89
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:7960c8e0-bba5-4602-0643-b58ff0021e66 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | CC10:3790:41D742E:577651F:696DE7C7 |
| html-safe-nonce | 923862648fe68a99230031af38174acc35fb7976d41288e35cd1812541481ab8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzEwOjM3OTA6NDFENzQyRTo1Nzc2NTFGOjY5NkRFN0M3IiwidmlzaXRvcl9pZCI6IjI4OTIyOTU4NDE0OTEzMTQ2MzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | eee1f95a7bcca7b267f54283406d616057618b2a637b1a76430d11b36b5508a4 |
| hovercard-subject-tag | pull_request:2695480932 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/sqlc-dev/sqlc-gen-python/pull/89/checks |
| twitter:image | https://avatars.githubusercontent.com/u/32516498?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/32516498?s=400&v=4 |
| og:image:alt | Fixes #88 To fix this issue, here is my proposition: class Author(pydantic.BaseModel): + model_config = pydantic.ConfigDict( + validate_by_alias=True, + validate_by_name=True, + ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064 |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlc-dev/sqlc-gen-python git https://github.com/sqlc-dev/sqlc-gen-python.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 548530161 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc-gen-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 548530161 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc-gen-python |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7e5ae23c70136152637ceee8d6faceb35596ec46 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width