Add schema generation hints to resolve warning #9046
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As a path to understanding the schema generator for #9045, I'm trying to address at least some of the warnings it currently produces.
/git/inventree/InvenTree/src/backend/InvenTree/company/serializers.py:107: Warning [CompanyList > CompanySerializer]: unable to resolve type hint for function "address". Consider using a type hint or @extend_schema_field. Defaulting to string.
String is actually the correct type in this case, but the field also needs to be nullable to be fully correct.
The two changes in this pull request accomplish the same goal: providing the nullable string type hint to the schema generator.
Adding a line to the serializer to explicitly define address produces:
while simply adding the return type hint to the model produces:
I would argue that the second option (adding type hints to the model) is the better way to go:
It's entirely possible that I'm missing something since I'm just focused on the schema, but the one (admittedly major) downside that I see to adding the hint to the model is that it doesn't match the way the existing serializers are set up.
Which route is preferable moving forward?