Skip to content

Commit 5435570

Browse files
authored
Fix update generation with additionalIdentifiers (#732)
* Disable unhelpful pylint warning pylint insists that `with` should be used on all disposable resources but in this case the constructor call is in a helper method and the consuming method does already use `with`. Given that this is a private method it should be fine to ignore the warning in all cases. * Fix update generation with additionalIdentifiers If the `additionalIdentifiers` property is present in a resource schema the `generate_update_example` method in `resource_client` will not work, because it checks for unique keys from the create_model and passes `self._additional_identifiers_paths` to a method that expects a list of tuples of string, whereas it receives a list of sets of tuples of string and will fail with ``` AttributeError: 'tuple' object has no attribute 'split' ``` Instead, check if the key is in any of the additional identifiers. Related issue ------------- #731
1 parent a9ab27a commit 5435570

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/rpdk/core/contract/resource_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,14 @@ def get_unique_keys_for_model(self, create_model):
290290
k: v
291291
for k, v in create_model.items()
292292
if self.is_property_in_path(k, self.primary_identifier_paths)
293-
or self.is_property_in_path(k, self._additional_identifiers_paths)
293+
or any(
294+
map(
295+
lambda additional_identifier_paths, key=k: self.is_property_in_path(
296+
key, additional_identifier_paths
297+
),
298+
self._additional_identifiers_paths,
299+
)
300+
)
294301
}
295302

296303
@staticmethod

src/rpdk/core/project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ def _create_context_manager(self, dry_run):
514514
# if it's a dry run, keep the file; otherwise can delete after upload
515515
if dry_run:
516516
return self._get_zip_file_path().open("wb")
517+
518+
# pylint: disable=consider-using-with
517519
return TemporaryFile("w+b")
518520

519521
def _get_zip_file_path(self):

tests/contract/test_resource_client.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@
8080
"primaryIdentifier": ["/properties/c", "/properties/d"],
8181
}
8282

83+
SCHEMA_WITH_ADDITIONAL_IDENTIFIERS = {
84+
"properties": {
85+
"a": {"type": "number"},
86+
"b": {"type": "number"},
87+
"c": {"type": "number"},
88+
"d": {"type": "number"},
89+
},
90+
"readOnlyProperties": ["/properties/b"],
91+
"createOnlyProperties": ["/properties/c"],
92+
"primaryIdentifier": ["/properties/c"],
93+
"additionalIdentifiers": [["/properties/b"]],
94+
}
95+
8396

8497
@pytest.fixture
8598
def resource_client():
@@ -157,8 +170,8 @@ def resource_client_inputs():
157170
return client
158171

159172

160-
@pytest.fixture
161-
def resource_client_inputs_schema():
173+
@pytest.fixture(params=[SCHEMA_, SCHEMA_WITH_ADDITIONAL_IDENTIFIERS])
174+
def resource_client_inputs_schema(request):
162175
endpoint = "https://"
163176
patch_sesh = patch(
164177
"rpdk.core.contract.resource_client.create_sdk_session", autospec=True
@@ -181,7 +194,7 @@ def resource_client_inputs_schema():
181194
DEFAULT_FUNCTION,
182195
endpoint,
183196
DEFAULT_REGION,
184-
SCHEMA_,
197+
request.param,
185198
EMPTY_OVERRIDE,
186199
{
187200
"CREATE": {"a": 111, "c": 2, "d": 3},
@@ -195,7 +208,7 @@ def resource_client_inputs_schema():
195208
mock_account.assert_called_once_with(mock_sesh, {})
196209

197210
assert client._function_name == DEFAULT_FUNCTION
198-
assert client._schema == SCHEMA_
211+
assert client._schema == request.param
199212
assert client._overrides == EMPTY_OVERRIDE
200213
assert client.account == ACCOUNT
201214

0 commit comments

Comments
 (0)