question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-editable, nullable (boolean) model field generates as required and not nullable

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
NANASHI0X74commented, Jul 2, 2021

and with that, my app finally compiles and lets me login again 🥳 partay ^^

0reactions
tfranzelcommented, Jul 8, 2021

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found