Skip to content

Since d28bc12 we generate broken code if there is a field called field #781

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

Closed
david-dotorigin opened this issue Jul 24, 2023 · 3 comments · Fixed by #793
Closed

Since d28bc12 we generate broken code if there is a field called field #781

david-dotorigin opened this issue Jul 24, 2023 · 3 comments · Fixed by #793
Labels
🐞bug Something isn't working
Milestone

Comments

@david-dotorigin
Copy link

david-dotorigin commented Jul 24, 2023

Describe the bug

Prior to d28bc12 the generated code says import attr afterwards the generated code says from attrs import define, field instead. This new import of field can be shadowed by a field called field. Resulting in generated code that makes Python complain:

some_dict: Dict[str, Any] = field(init=False, factory=dict)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'Unset' object is not callable

To Reproduce

Put the OpenAPI Spec File below into demo.json.

Put this Python into demo.py:

import sys
sys.path.append('demo-api-client')
from demo_api_client.models import *

Then give these commands:

openapi-python-client generate --path demo.json
demo.py

The response from demo.py is

Traceback (most recent call last):
  File "C:\projects\dot\openapi-python-client7\demo.py", line 4, in <module>
	from demo_api_client.models.get_user_response_200 import GetUserResponse200
  File "C:\projects\dot\openapi-python-client7\demo-api-client\demo_api_client\models\__init__.py", line 3, in <module>
	from .field_defs import FieldDefs
  File "C:\projects\dot\openapi-python-client7\demo-api-client\demo_api_client\models\field_defs.py", line 11, in <module>
	class FieldDefs:
  File "C:\projects\dot\openapi-python-client7\demo-api-client\demo_api_client\models\field_defs.py", line 18, in FieldDefs
	additional_properties: Dict[str, Any] = field(init=False, factory=dict)
											^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'Unset' object is not callable

Expected behavior
A field called field should continue to work.

OpenAPI Spec File

{
	"openapi": "3.0.3",
	"servers": [
		{
			"url": "https://localhost:8080",
			"description": "___"
		}
	],
	"info": {
		"title": "Demo API",
		"version": "1.1.1"
	},
	"paths": {
		"/user": {
			"get": {
				"description": "___",
				"responses": {
					"200": {
						"description": "___"
					}
				},
				"summary": "___",
				"tags": [
					"utility"
				]
			}
		}
	},
	"components": {
		"schemas": {
			"FieldDefs": {
				"type": "object",
				"properties": {
					"field": {
						"type": "string",
						"description": "___"
					}
				}
			}
		}
	}
}
@david-dotorigin david-dotorigin added the 🐞bug Something isn't working label Jul 24, 2023
@dbanty
Copy link
Collaborator

dbanty commented Jul 26, 2023

Whoops! Thanks for reporting, I'll prioritize fixing this!

@dbanty dbanty added this to the 0.15.1 milestone Jul 26, 2023
@david-dotorigin
Copy link
Author

david-dotorigin commented Jul 29, 2023

Good news. Thank you!

For now, as I work around, I'm using the previous version pip install openapi-python-client==0.14.1.

@odaom
Copy link

odaom commented Aug 2, 2023

I have this issue as well, thanks for prioritizing it!

dbanty added a commit that referenced this issue Aug 12, 2023
…781, #793). Thanks @david-dotorigin

* fix: Naming conflicts when properties are named "field" or "define"

Closes #781

* Add missing generated files

---------

Co-authored-by: Dylan Anthony <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
3 participants