Skip to content

Render optional attributes with default values as mandatory#909

Draft
ogenstad wants to merge 1 commit intostablefrom
pog-mandatory-default-attributes-IHS-216
Draft

Render optional attributes with default values as mandatory#909
ogenstad wants to merge 1 commit intostablefrom
pog-mandatory-default-attributes-IHS-216

Conversation

@ogenstad
Copy link
Copy Markdown
Contributor

Why

Currently when you create a schema in Infrahub with a node that has a mandatory attribute and that attribute has a default value, then Infrahub will update the schema definition and mark the attribute as optional. The intention is to change this behaviour, until that happens we want to update the protocol definitions that are generated out of such a schema so that the attributes appear to be required (a separate PR will be opened against the Infrahub repo to disallow changing such attributes to a null value.

Closes #894.

What changed

  • Update the Jinja2 template to only mark an attribute as optional in the generated protocols if it both is optional and doesn't have a default value.

Impact & rollout

At some later date we'll want to revert this in order to properly support schemas where the user wants these attributes to actually be optional (and nullable) even though they have a default_value set.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 551192b2-4754-48d2-8409-2c67659361f4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable     #909      +/-   ##
==========================================
+ Coverage   72.91%   80.71%   +7.80%     
==========================================
  Files         119      119              
  Lines       10336    10336              
  Branches     1551     1551              
==========================================
+ Hits         7536     8343     +807     
+ Misses       2287     1469     -818     
- Partials      513      524      +11     
Flag Coverage Δ
integration-tests 41.75% <0.00%> (?)
python-3.10 51.84% <100.00%> (ø)
python-3.11 51.84% <100.00%> (+0.01%) ⬆️
python-3.12 51.84% <100.00%> (+0.01%) ⬆️
python-3.13 51.82% <100.00%> (-0.02%) ⬇️
python-3.14 53.54% <100.00%> (ø)
python-filler-3.12 24.04% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/protocols_generator/generator.py 95.00% <100.00%> (ø)

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Mandatory fields with default_value set incorrectly have Optional type in schema protocols

1 participant