René's URL Explorer Experiment


Title: New behavior around optional nested objects breaks deserialization when explicit null is returned · Issue #343 · openapi-generators/openapi-python-client · GitHub

Open Graph Title: New behavior around optional nested objects breaks deserialization when explicit null is returned · Issue #343 · openapi-generators/openapi-python-client

X Title: New behavior around optional nested objects breaks deserialization when explicit null is returned · Issue #343 · openapi-generators/openapi-python-client

Description: Describe the bug We use FastAPI as an API server and generate a python client with open-api-client that is then used to run integration tests. Our team is using 0.7.3 but I was trying to update to 0.8.0. When doing so, we ran into the fo...

Open Graph Description: Describe the bug We use FastAPI as an API server and generate a python client with open-api-client that is then used to run integration tests. Our team is using 0.7.3 but I was trying to update to ...

X Description: Describe the bug We use FastAPI as an API server and generate a python client with open-api-client that is then used to run integration tests. Our team is using 0.7.3 but I was trying to update to ...

Opengraph URL: https://github.com/openapi-generators/openapi-python-client/issues/343

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"New behavior around optional nested objects breaks deserialization when explicit null is returned","articleBody":"**Describe the bug**\r\nWe use FastAPI as an API server and generate a python client with `open-api-client` that is then used to run integration tests.  Our team is using 0.7.3 but I was trying to update to 0.8.0.  When doing so, we ran into the following exception running our test suite:\r\n```\r\n/usr/local/lib/python3.8/site-packages/falkon_sdk/api/observations/get_observations.py:73: in _parse_response\r\n    response_200 = ObservationResult.from_dict(response.json())\r\n/usr/local/lib/python3.8/site-packages/falkon_sdk/models/observation_result.py:104: in from_dict\r\n    metric_change = ObservationFactWindowSummaryResource.from_dict(\r\n/usr/local/lib/python3.8/site-packages/falkon_sdk/models/observation_fact_window_summary_resource.py:156: in from_dict\r\n    weighted_change_unfiltered = WeightedChange.from_dict(\r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \r\n\r\ncls = \u003cclass 'falkon_sdk.models.weighted_change.WeightedChange'\u003e\r\nsrc_dict = None\r\n\r\n    @classmethod\r\n    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -\u003e T:\r\n\u003e       d = src_dict.copy()\r\nE       AttributeError: 'NoneType' object has no attribute 'copy'\r\n```\r\n\r\nI was able to narrow down the problem to handling of `Optional[T]` objects within response models.  Here is a minimal repro:\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Make a main.py file with the following contents:\r\n```\r\nfrom typing import Optional\r\nfrom fastapi import FastAPI\r\nfrom pydantic import BaseModel\r\n\r\napp = FastAPI()\r\n\r\nclass ItemResource(BaseModel):\r\n    id: int\r\n\r\nclass ResourceWithOptional(BaseModel):\r\n    item: Optional[ItemResource]\r\n\r\n@app.get(\"/\", response_model=ResourceWithOptional)\r\ndef read_item():\r\n    return ResourceWithOptional(item=None)\r\n```\r\n2.  Start it up in uvicorn\r\n```\r\nuvicorn main:app \u0026\r\n```\r\n2.  Curling that endpoint returns this:\r\n```\r\ncurl -s http://localhost:8000/\r\nINFO:     127.0.0.1:32770 - \"GET / HTTP/1.1\" 200 OK\r\n{\"item\":null}\r\n```\r\n\r\n3.  Generate a client for this:\r\n```\r\nopenapi-python-client generate --url http://localhost:8000/openapi.json\r\n```\r\n\r\n4.  Look at the generated `resource_with_optional.py` in the `from_dict` method:\r\n```\r\n        item: Union[ItemResource, Unset] = UNSET\r\n        _item = d.pop(\"item\", UNSET)\r\n        if not isinstance(_item, Unset):\r\n            item = ItemResource.from_dict(_item)\r\n```\r\n\r\n**Expected behavior**\r\nI expect that this allows for an explicit `null` to be returned, as was the case in openapi-python-client==0.7.3, where the generated code looks like this:\r\n```\r\n        item: Union[ItemResource, Unset] = UNSET\r\n        _item = d.pop(\"item\", UNSET)\r\n        if _item is not None and not isinstance(_item, Unset):\r\n            item = ItemResource.from_dict(cast(Dict[str, Any], _item))\r\n```\r\n\r\n**OpenAPI Spec File**\r\n```\r\n{\"openapi\":\"3.0.2\",\"info\":{\"title\":\"FastAPI\",\"version\":\"0.1.0\"},\"paths\":{\"/\":{\"get\":{\"summary\":\"Read Item\",\"operationId\":\"read_item__get\",\"responses\":{\"200\":{\"description\":\"Successful Response\",\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/ResourceWithOptional\"}}}}}}}},\"components\":{\"schemas\":{\"ItemResource\":{\"title\":\"ItemResource\",\"required\":[\"id\"],\"type\":\"object\",\"properties\":{\"id\":{\"title\":\"Id\",\"type\":\"integer\"}}},\"ResourceWithOptional\":{\"title\":\"ResourceWithOptional\",\"type\":\"object\",\"properties\":{\"item\":{\"$ref\":\"#/components/schemas/ItemResource\"}}}}}}\r\n```\r\n\r\n**Desktop (please complete the following information):**\r\n - OS: Ubuntu Linux 20.04\r\n - Python Version: 3.8.6\r\n - openapi-python-client version 0.8.0\r\n\r\n**Additional context**\r\nFastAPI has support for excluding nulls from responses with `response_model_exclude_none` but this means changing how our API works to suit the sdk generator, which I would prefer not to have to do.\r\nThe new behavior I was referring to seems to have come in with #334 \r\n","author":{"url":"https://github.com/joshzana","@type":"Person","name":"joshzana"},"datePublished":"2021-03-03T05:48:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/343/openapi-python-client/issues/343"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b9b548ac-e39e-eeb3-7dde-b76fbf3cbdb0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE592:3836D9:7A2B697:A29AC38:6980C089
html-safe-nonce0e43a134ed805a2a286956fd1f96c07a033d4e94b31d446df0e30c8ce97d461e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTkyOjM4MzZEOTo3QTJCNjk3OkEyOUFDMzg6Njk4MEMwODkiLCJ2aXNpdG9yX2lkIjoiODExNDE1MDcxNjkwMzc1MzA1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac589cfac623f34201d458d18d9dfb4d92f2e5ba318a3da4008921e42c8de80acf
hovercard-subject-tagissue:820767495
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openapi-generators/openapi-python-client/343/issue_layout
twitter:imagehttps://opengraph.githubassets.com/15fe8c53089cee88dc2245234cf031d1333e2fdd040611185299dd22baf1a3d1/openapi-generators/openapi-python-client/issues/343
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/15fe8c53089cee88dc2245234cf031d1333e2fdd040611185299dd22baf1a3d1/openapi-generators/openapi-python-client/issues/343
og:image:altDescribe the bug We use FastAPI as an API server and generate a python client with open-api-client that is then used to run integration tests. Our team is using 0.7.3 but I was trying to update to ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejoshzana
hostnamegithub.com
expected-hostnamegithub.com
Nonefb936832e40deb3175641d9cfedc8432372f91b0bc899576222953095fc7879e
turbo-cache-controlno-preview
go-importgithub.com/openapi-generators/openapi-python-client git https://github.com/openapi-generators/openapi-python-client.git
octolytics-dimension-user_id84925606
octolytics-dimension-user_loginopenapi-generators
octolytics-dimension-repository_id240776275
octolytics-dimension-repository_nwoopenapi-generators/openapi-python-client
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id240776275
octolytics-dimension-repository_network_root_nwoopenapi-generators/openapi-python-client
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release3e9b7987a76a2b9d08066d02bb64947a61943332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/openapi-generators/openapi-python-client/issues/343#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenapi-generators%2Fopenapi-python-client%2Fissues%2F343
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenapi-generators%2Fopenapi-python-client%2Fissues%2F343
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=openapi-generators%2Fopenapi-python-client
Reloadhttps://github.com/openapi-generators/openapi-python-client/issues/343
Reloadhttps://github.com/openapi-generators/openapi-python-client/issues/343
Reloadhttps://github.com/openapi-generators/openapi-python-client/issues/343
openapi-generators https://github.com/openapi-generators
openapi-python-clienthttps://github.com/openapi-generators/openapi-python-client
Please reload this pagehttps://github.com/openapi-generators/openapi-python-client/issues/343
Notifications https://github.com/login?return_to=%2Fopenapi-generators%2Fopenapi-python-client
Fork 264 https://github.com/login?return_to=%2Fopenapi-generators%2Fopenapi-python-client
Star 1.9k https://github.com/login?return_to=%2Fopenapi-generators%2Fopenapi-python-client
Code https://github.com/openapi-generators/openapi-python-client
Issues 77 https://github.com/openapi-generators/openapi-python-client/issues
Pull requests 14 https://github.com/openapi-generators/openapi-python-client/pulls
Discussions https://github.com/openapi-generators/openapi-python-client/discussions
Actions https://github.com/openapi-generators/openapi-python-client/actions
Security 2 https://github.com/openapi-generators/openapi-python-client/security
Insights https://github.com/openapi-generators/openapi-python-client/pulse
Code https://github.com/openapi-generators/openapi-python-client
Issues https://github.com/openapi-generators/openapi-python-client/issues
Pull requests https://github.com/openapi-generators/openapi-python-client/pulls
Discussions https://github.com/openapi-generators/openapi-python-client/discussions
Actions https://github.com/openapi-generators/openapi-python-client/actions
Security https://github.com/openapi-generators/openapi-python-client/security
Insights https://github.com/openapi-generators/openapi-python-client/pulse
New issuehttps://github.com/login?return_to=https://github.com/openapi-generators/openapi-python-client/issues/343
New issuehttps://github.com/login?return_to=https://github.com/openapi-generators/openapi-python-client/issues/343
New behavior around optional nested objects breaks deserialization when explicit null is returnedhttps://github.com/openapi-generators/openapi-python-client/issues/343#top
https://github.com/dbanty
🐞bugSomething isn't workinghttps://github.com/openapi-generators/openapi-python-client/issues?q=state%3Aopen%20label%3A%22%F0%9F%90%9Ebug%22
0.9.0https://github.com/openapi-generators/openapi-python-client/milestone/19
https://github.com/joshzana
https://github.com/joshzana
joshzanahttps://github.com/joshzana
on Mar 3, 2021https://github.com/openapi-generators/openapi-python-client/issues/343#issue-820767495
#334https://github.com/openapi-generators/openapi-python-client/pull/334
dbantyhttps://github.com/dbanty
🐞bugSomething isn't workinghttps://github.com/openapi-generators/openapi-python-client/issues?q=state%3Aopen%20label%3A%22%F0%9F%90%9Ebug%22
0.9.0https://github.com/openapi-generators/openapi-python-client/milestone/19
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.