Non-editable, nullable (boolean) model field generates as required and not nullable
See original GitHub issueDescribe the bug As title says.
To Reproduce A model with a field like this:
class User(AbstractUser):
invite = models.BooleanField(editable=False, null=True)
will produce a schema component like this:
UserDetail:
type: object
properties:
invite:
type: boolean
readOnly: true
required:
- invite
this is a problem in nullsafe code generators because this field will be a non-nullable property and if the property is null, deserializing it will throw an error. for reference, settings:
'ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE': False,
'COMPONENT_SPLIT_REQUEST': True,
Expected behavior Either have a nullable boolean field (if openapi allows that) or not have the field be required.
Workaround
setting 'COMPONENT_NO_READ_ONLY_REQUIRED': True
will fix this, but isn’t ideal, because id fields among others may then get generated as nullable
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
c# - Why do nullable bools not allow if ... - Stack Overflow
public struct DBInt { // The Null member represents an unknown DBInt value. public static readonly DBInt Null = new DBInt(); // When...
Read more >Nullable value types - C# reference - Microsoft Learn
You typically use a nullable value type when you need to represent the undefined value of an underlying value type. For example, a...
Read more >Scaffolding doesn't allow nullable: false to return required ...
The way it manifests for me is using the fields plugin to automatically generate scaffolding, so having a domain class with a Boolean...
Read more >Model field reference - Django documentation
If True , Django will store empty values as NULL in the database. Default is False . Avoid using null on string-based fields...
Read more >Dart Null Safety: The Ultimate Guide to Non-Nullable Types
But type safety alone can't guarantee that a variable (or return value) is not null . As a result this code compiles, but...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
and with that, my app finally compiles and lets me login again 🥳 partay ^^
i’ll close this issue for now as i consider this mostly an upstream issue. if someone has a good idea on how to fix this, i’m all ears!