Skip to content

WIP Parameter model#208

Open
albertsola wants to merge 1 commit intomainfrom
asola/improve_parameters_model
Open

WIP Parameter model#208
albertsola wants to merge 1 commit intomainfrom
asola/improve_parameters_model

Conversation

@albertsola
Copy link
Contributor

@albertsola albertsola commented Feb 9, 2026

Parameter Model Improvements

  • Enhanced internal attribute mapping: MptBox now copies attribute_mapping on init to prevent external mutations.
  • Key normalization and mapping fixes: _prep_key avoids overwriting existing mappings, returns already-mapped keys, caches camelCase mappings from _camel_killer; setitem and setattr store values under prepared/mapped keys; to_dict falls back to original keys when reverse mapping is missing.
  • Model attribute behavior: Model.setattr now respects class descriptors (properties with setters) and invokes them instead of delegating to the box.
  • Parameter API model additions: Added Parameter.attribute_mapping = {"externalId": "external_id"} and new typed properties on Parameter — type, scope, phase, context, options, multiple, constraints, group, external_id, and status — backed by the internal model box.
  • Tests: Added unit tests covering Parameter getters, setters, default values, and to_dict output.

@albertsola albertsola requested a review from a team as a code owner February 9, 2026 16:04
@albertsola albertsola requested review from alephsur and jentyk February 9, 2026 16:04
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

Model attribute-mapping/storage now uses prepared mapped keys and copies mappings to avoid external mutation; Model respects class descriptors when setting attributes. The Parameter resource adds a class attribute mapping and multiple property accessors (including type_ and external_id) persisted via the model box. Unit tests added for Parameter.

Changes

Cohort / File(s) Summary
Base model updates
mpt_api_client/models/model.py
Store a copied attribute_mapping on init; MptBox now stores values under keys returned by _prep_key; _prep_key avoids overwriting existing mappings and caches new mapped keys; to_dict uses reverse_mapping.get(parsed_key, parsed_key) to avoid KeyError; Model.__setattr__ respects class descriptors (invokes property setters when present).
Parameter resource additions
mpt_api_client/resources/catalog/products_parameters.py
Add Parameter._attribute_mapping: ClassVar[dict[str,str]] = {"externalId": "external_id"} and add property accessors (getters/setters) for type_, scope, phase, context, options, multiple, constraints, group, external_id, and status, backed by the model box.
Tests for Parameter properties
tests/unit/resources/catalog/test_parameter_properties.py
Add unit tests validating Parameter getters, setters, default values, and to_dict() serialization (including camelCase externalId).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Jira Issue Key In Title ❌ Error PR title does not contain a Jira issue key in the format MPT-XXXX. Update the PR title to include the Jira issue key in the format MPT-XXXX (e.g., MPT-XXXX: WIP Parameter model).
✅ Passed checks (2 passed)
Check name Status Explanation
Test Coverage Required ✅ Passed The PR modifies 2 code files and includes test file changes with 76 lines of new test coverage.
Single Commit Required ✅ Passed The pull request contains exactly one commit (b256d60 Parameter model Proof of concept), which satisfies the single commit requirement.

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

@albertsola albertsola force-pushed the asola/improve_parameters_model branch from b4f0443 to b2a8184 Compare February 17, 2026 14:19
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/unit/resources/catalog/test_parameter_properties.py (1)

4-4: Remove invalid # noqa: WPS218 directives.

Ruff does not recognize WPS218 (a wemake-python-styleguide rule). Since this project uses Ruff for linting, these directives have no effect and should be removed.

♻️ Proposed fix
-def test_parameter_properties_getters():  # noqa: WPS218
+def test_parameter_properties_getters():
-def test_parameter_properties_setters():  # noqa: WPS218
+def test_parameter_properties_setters():
-def test_parameter_default_values():  # noqa: WPS218
+def test_parameter_default_values():

Also applies to: 32-32, 64-64

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/resources/catalog/test_parameter_properties.py` at line 4, Remove
the invalid Ruff-ignore directives by deleting the `# noqa: WPS218` comment from
the test function declaration `test_parameter_properties_getters` (and the two
other occurrences flagged in the same file), since Ruff does not recognize
`WPS218`; simply remove the `# noqa: WPS218` tokens so the function defs are
clean (e.g., change `def test_parameter_properties_getters():  # noqa: WPS218`
to `def test_parameter_properties_getters():`) and repeat for the other two
occurrences.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/resources/catalog/test_parameter_properties.py`:
- Around line 58-61: The test contains duplicate assertions on result_dict
("scope" == "Agreement" and "externalId" == "ext-2") in
test_parameter_properties.py; remove the repeated assertions so each check for
result_dict["scope"] and result_dict["externalId"] appears only once, leaving a
single pair of asserts referencing result_dict to avoid redundant assertions.
- Line 37: Add an explicit property for type_ on the Parameter class consistent
with the other parameter attributes: implement a `@property` def type_(self) that
returns self._box.type_ (or getattr(self._box, "type_", None)) and a setter def
type_(self, value) that sets self._box.type_ = value (or uses setattr) and
mirrors any validation/behavior used by other properties like scope/phase;
update the Parameter class to include these getter and setter methods so type_
is treated the same way as scope, phase, context, options, multiple,
constraints, group, external_id, and status.

---

Nitpick comments:
In `@tests/unit/resources/catalog/test_parameter_properties.py`:
- Line 4: Remove the invalid Ruff-ignore directives by deleting the `# noqa:
WPS218` comment from the test function declaration
`test_parameter_properties_getters` (and the two other occurrences flagged in
the same file), since Ruff does not recognize `WPS218`; simply remove the `#
noqa: WPS218` tokens so the function defs are clean (e.g., change `def
test_parameter_properties_getters():  # noqa: WPS218` to `def
test_parameter_properties_getters():`) and repeat for the other two occurrences.

Comment on lines +58 to +61
assert result_dict["scope"] == "Agreement"
assert result_dict["externalId"] == "ext-2"
assert result_dict["scope"] == "Agreement"
assert result_dict["externalId"] == "ext-2"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove duplicate assertions.

Lines 60-61 are exact duplicates of lines 58-59. This appears to be a copy-paste error.

🧹 Proposed fix
     result_dict = result.to_dict()
     assert result_dict["scope"] == "Agreement"
     assert result_dict["externalId"] == "ext-2"
-    assert result_dict["scope"] == "Agreement"
-    assert result_dict["externalId"] == "ext-2"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assert result_dict["scope"] == "Agreement"
assert result_dict["externalId"] == "ext-2"
assert result_dict["scope"] == "Agreement"
assert result_dict["externalId"] == "ext-2"
assert result_dict["scope"] == "Agreement"
assert result_dict["externalId"] == "ext-2"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/resources/catalog/test_parameter_properties.py` around lines 58 -
61, The test contains duplicate assertions on result_dict ("scope" ==
"Agreement" and "externalId" == "ext-2") in test_parameter_properties.py; remove
the repeated assertions so each check for result_dict["scope"] and
result_dict["externalId"] appears only once, leaving a single pair of asserts
referencing result_dict to avoid redundant assertions.

@albertsola albertsola force-pushed the asola/improve_parameters_model branch from b2a8184 to b256d60 Compare February 17, 2026 14:34
@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@tests/unit/resources/catalog/test_parameter_properties.py`:
- Around line 32-61: The test test_parameter_properties_setters contains
duplicated assertions checking result_dict["scope"] and
result_dict["externalId"]; remove the redundant second pair so only one
assertion for each key remains (locate the assertions after result_dict =
result.to_dict() and delete the duplicated lines asserting "scope" and
"externalId").

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.

1 participant