Skip to content

Conversation

@ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Apr 14, 2025

This PR cleans up the initialization code for setting attributes and relationships within InfrahubNode objects. The problem here is that we iterate over the names of self._attributes and then we have to iterate the self._schema.attributes and assume that there will always be a match (the [0] part), we'll always have a match here but it looks a bit off. The self._attributes property will also use the schema listing to find the names to the part is pretty much just redundant. The same thing is happening for the relationships.

I started to think about this during the weekend when considering how we could remove the way nodes are dynamically generated each time we initialize a new node using the SDK. In short I think we should replace the current setattr, calls to generate_relationship_property and self.__class__ = type(f"{schema.kind}InfrahubNode", (self.__class__,), {}) within the __init__() method and transition to using a custom __getattr__ method where this is handled instead.

@cloudflare-workers-and-pages
Copy link

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: bae5fba
Status: ✅  Deploy successful!
Preview URL: https://c7d52002.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-init-cleanup.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

@@             Coverage Diff             @@
##           develop     #355      +/-   ##
===========================================
- Coverage    72.45%   72.44%   -0.02%     
===========================================
  Files           91       91              
  Lines         8180     8177       -3     
  Branches      1576     1573       -3     
===========================================
- Hits          5927     5924       -3     
  Misses        1841     1841              
  Partials       412      412              
Flag Coverage Δ
integration-tests 22.31% <60.00%> (-0.02%) ⬇️
python-3.10 46.52% <100.00%> (-0.02%) ⬇️
python-3.11 46.52% <100.00%> (+<0.01%) ⬆️
python-3.12 46.49% <100.00%> (-0.05%) ⬇️
python-3.13 46.52% <100.00%> (-0.02%) ⬇️
python-3.9 44.84% <100.00%> (-0.05%) ⬇️
python-filler-3.12 25.10% <0.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
infrahub_sdk/node.py 77.32% <100.00%> (-0.07%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ogenstad ogenstad requested a review from a team April 14, 2025 07:28
@ogenstad ogenstad merged commit 082559e into develop Apr 15, 2025
18 checks passed
@ogenstad ogenstad deleted the pog-init-cleanup branch April 15, 2025 06:13
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.

2 participants