Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bct] Misc fixes #36966

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions scripts/breaking_changes_checker/breaking_changes_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,46 +468,47 @@ def check_positional_parameter_removed_or_renamed(
)

def check_class_instance_attribute_removed_or_renamed(self, components: Dict) -> None:
deleted_props = []
for prop in components.get("properties", []):
if isinstance(prop, jsondiff.Symbol):
deleted_props = []
if prop.label == "delete":
deleted_props = components["properties"][prop]
elif prop.label == "replace":
deleted_props = self.stable[self.module_name]["class_nodes"][self.class_name]["properties"]

for property in deleted_props:
bc = None
if self.class_name.endswith("Client"):
property_type = self.stable[self.module_name]["class_nodes"][self.class_name]["properties"][property]["attr_type"]
if property_type is not None and property_type.lower().endswith("operations"):
bc = (
self.REMOVED_OR_RENAMED_OPERATION_GROUP_MSG,
catalinaperalta marked this conversation as resolved.
Show resolved Hide resolved
BreakingChangeType.REMOVED_OR_RENAMED_OPERATION_GROUP,
self.module_name, self.class_name, property
)
else:
bc = (
self.REMOVED_OR_RENAMED_INSTANCE_ATTRIBUTE_FROM_CLIENT_MSG,
BreakingChangeType.REMOVED_OR_RENAMED_INSTANCE_ATTRIBUTE,
self.module_name, self.class_name, property
)
elif self.stable[self.module_name]["class_nodes"][self.class_name]["type"] == "Enum":
if property.upper() not in self.current[self.module_name]["class_nodes"][self.class_name]["properties"] \
and property.lower() not in self.current[self.module_name]["class_nodes"][self.class_name]["properties"]:
bc = (
self.REMOVED_OR_RENAMED_ENUM_VALUE_MSG,
BreakingChangeType.REMOVED_OR_RENAMED_ENUM_VALUE,
self.module_name, self.class_name, property
)
else:
for property in deleted_props:
bc = None
if self.class_name.endswith("Client"):
property_type = self.stable[self.module_name]["class_nodes"][self.class_name]["properties"][property]["attr_type"]
# property_type is not always a string, such as client_side_validation which is a bool, so we need to check for strings
if property_type is not None and isinstance(property_type, str) and property_type.lower().endswith("operations"):
bc = (
self.REMOVED_OR_RENAMED_INSTANCE_ATTRIBUTE_FROM_MODEL_MSG,
BreakingChangeType.REMOVED_OR_RENAMED_INSTANCE_ATTRIBUTE,
self.REMOVED_OR_RENAMED_OPERATION_GROUP_MSG,
BreakingChangeType.REMOVED_OR_RENAMED_OPERATION_GROUP,
self.module_name, self.class_name, property
)
if bc:
self.breaking_changes.append(bc)
else:
bc = (
self.REMOVED_OR_RENAMED_INSTANCE_ATTRIBUTE_FROM_CLIENT_MSG,
BreakingChangeType.REMOVED_OR_RENAMED_INSTANCE_ATTRIBUTE,
self.module_name, self.class_name, property
)
elif self.stable[self.module_name]["class_nodes"][self.class_name]["type"] == "Enum":
if property.upper() not in self.current[self.module_name]["class_nodes"][self.class_name]["properties"] \
and property.lower() not in self.current[self.module_name]["class_nodes"][self.class_name]["properties"]:
bc = (
self.REMOVED_OR_RENAMED_ENUM_VALUE_MSG,
BreakingChangeType.REMOVED_OR_RENAMED_ENUM_VALUE,
self.module_name, self.class_name, property
)
else:
bc = (
self.REMOVED_OR_RENAMED_INSTANCE_ATTRIBUTE_FROM_MODEL_MSG,
BreakingChangeType.REMOVED_OR_RENAMED_INSTANCE_ATTRIBUTE,
self.module_name, self.class_name, property
)
if bc:
self.breaking_changes.append(bc)

def check_class_removed_or_renamed(self, class_components: Dict) -> Union[bool, None]:
if isinstance(self.class_name, jsondiff.Symbol):
Expand Down Expand Up @@ -625,8 +626,11 @@ def report_changes(self) -> None:

formatted = "\n"
for idx, bc in enumerate(self.breaking_changes):
# Extract the message and the change type, skip the module name
msg, bc_type, _, *args = bc
msg, bc_type, module_name, *args = bc
if bc_type == BreakingChangeType.REMOVED_OR_RENAMED_MODULE:
# For module-level changes, the module name is the first argument
formatted += f"({bc_type}): " + msg.format(module_name) + "\n"
continue
# For simple breaking changes reporting, prepend the change code to the message
msg = f"({bc_type}): " + msg + "\n"
formatted += msg.format(*args)
Expand Down
64 changes: 32 additions & 32 deletions scripts/breaking_changes_checker/tests/test_breaking_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ def format_breaking_changes(breaking_changes):
return formatted

EXPECTED = [
"(RemovedOrRenamedInstanceAttribute): The model or publicly exposed class 'azure.storage.queue.Metrics' had its instance variable 'retention_policy' deleted or renamed in the current version",
"(RemovedOrRenamedInstanceAttribute): The client 'azure.storage.queue.QueueClient' had its instance variable 'queue_name' deleted or renamed in the current version",
"(ChangedParameterKind): The class 'azure.storage.queue.QueueClient' method 'from_queue_url' had its parameter 'credential' changed from 'positional_or_keyword' to 'keyword_only' in the current version",
"(AddedPositionalParam): The 'azure.storage.queue.QueueClient' method 'get_queue_access_policy' had a 'positional_or_keyword' parameter 'queue_name' inserted in the current version",
"(RemovedOrRenamedPositionalParam): The 'azure.storage.queue.QueueClient' method 'set_queue_access_policy' had its parameter 'signed_identifiers' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(ChangedParameterDefaultValue): The class 'azure.storage.queue.QueueClient' method 'set_queue_metadata' had its parameter 'metadata' default value changed from 'None' to ''",
"(RemovedOrRenamedClassMethod): The 'azure.storage.queue.QueueSasPermissions' method 'from_string' was deleted or renamed in the current version",
"(RemovedFunctionKwargs): The class 'azure.storage.queue.QueueServiceClient' method 'set_service_properties' changed from accepting keyword arguments to not accepting them in the current version",
"(RemovedOrRenamedClientMethod): The 'azure.storage.queue.QueueServiceClient' client method 'get_service_properties' was deleted or renamed in the current version",
"(RemovedOrRenamedEnumValue): The 'azure.storage.queue.StorageErrorCode' enum had its value 'queue_not_found' deleted or renamed in the current version",
"(RemovedOrRenamedClass): The model or publicly exposed class 'azure.storage.queue.QueueMessage' was deleted or renamed in the current version",
"(ChangedParameterDefaultValue): The publicly exposed function 'azure.storage.queue.generate_queue_sas' had its parameter 'permission' default value changed from 'None' to ''",
"(ChangedParameterKind): The function 'azure.storage.queue.generate_queue_sas' had its parameter 'ip' changed from 'positional_or_keyword' to 'keyword_only' in the current version",
"(AddedPositionalParam): The function 'azure.storage.queue.generate_queue_sas' had a 'positional_or_keyword' parameter 'conn_str' inserted in the current version",
"(RemovedOrRenamedPositionalParam): The function 'azure.storage.queue.generate_queue_sas' had its parameter 'account_name' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(RemovedOrRenamedModuleLevelFunction): The publicly exposed function 'azure.storage.queue.generate_account_sas' was deleted or renamed in the current version",
"(ChangedParameterKind): The class 'azure.storage.queue.aio.QueueClient' method 'from_queue_url' had its parameter 'credential' changed from 'positional_or_keyword' to 'keyword_only' in the current version",
"(RemovedParameterDefaultValue): The class 'azure.storage.queue.aio.QueueClient' method 'update_message' had default value 'None' removed from its parameter 'pop_receipt' in the current version",
"(ChangedFunctionKind): The class 'azure.storage.queue.aio.QueueServiceClient' method 'get_service_stats' changed from 'asynchronous' to 'synchronous' in the current version.",
"(ChangedParameterOrdering): The class 'azure.storage.queue.QueueClient' method 'from_connection_string' had its parameters re-ordered from '['conn_str', 'queue_name', 'credential', 'kwargs']' to '['queue_name', 'conn_str', 'credential', 'kwargs']' in the current version",
"(ChangedParameterOrdering): The class 'azure.storage.queue.aio.QueueClient' method 'from_connection_string' had its parameters re-ordered from '['conn_str', 'queue_name', 'credential', 'kwargs']' to '['queue_name', 'conn_str', 'credential', 'kwargs']' in the current version",
catalinaperalta marked this conversation as resolved.
Show resolved Hide resolved
"(RemovedOrRenamedInstanceAttribute): The model or publicly exposed class 'Metrics' had its instance variable 'retention_policy' deleted or renamed in the current version",
"(RemovedOrRenamedInstanceAttribute): The client 'QueueClient' had its instance variable 'queue_name' deleted or renamed in the current version",
"(ChangedParameterKind): The class 'QueueClient' method 'from_queue_url' had its parameter 'credential' changed from 'positional_or_keyword' to 'keyword_only' in the current version",
"(AddedPositionalParam): The 'QueueClient' method 'get_queue_access_policy' had a 'positional_or_keyword' parameter 'queue_name' inserted in the current version",
"(RemovedOrRenamedPositionalParam): The 'QueueClient' method 'set_queue_access_policy' had its parameter 'signed_identifiers' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(ChangedParameterDefaultValue): The class 'QueueClient' method 'set_queue_metadata' had its parameter 'metadata' default value changed from 'None' to ''",
"(RemovedOrRenamedClassMethod): The 'QueueSasPermissions' method 'from_string' was deleted or renamed in the current version",
"(RemovedFunctionKwargs): The class 'QueueServiceClient' method 'set_service_properties' changed from accepting keyword arguments to not accepting them in the current version",
"(RemovedOrRenamedClientMethod): The 'QueueServiceClient' client method 'get_service_properties' was deleted or renamed in the current version",
"(RemovedOrRenamedEnumValue): The 'StorageErrorCode' enum had its value 'queue_not_found' deleted or renamed in the current version",
"(RemovedOrRenamedClass): The model or publicly exposed class 'QueueMessage' was deleted or renamed in the current version",
"(ChangedParameterDefaultValue): The publicly exposed function 'generate_queue_sas' had its parameter 'permission' default value changed from 'None' to ''",
"(ChangedParameterKind): The function 'generate_queue_sas' had its parameter 'ip' changed from 'positional_or_keyword' to 'keyword_only' in the current version",
"(AddedPositionalParam): The function 'generate_queue_sas' had a 'positional_or_keyword' parameter 'conn_str' inserted in the current version",
"(RemovedOrRenamedPositionalParam): The function 'generate_queue_sas' had its parameter 'account_name' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(RemovedOrRenamedModuleLevelFunction): The publicly exposed function 'generate_account_sas' was deleted or renamed in the current version",
"(ChangedParameterKind): The class 'QueueClient' method 'from_queue_url' had its parameter 'credential' changed from 'positional_or_keyword' to 'keyword_only' in the current version",
"(RemovedParameterDefaultValue): The class 'QueueClient' method 'update_message' had default value 'None' removed from its parameter 'pop_receipt' in the current version",
"(ChangedFunctionKind): The class 'QueueServiceClient' method 'get_service_stats' changed from 'asynchronous' to 'synchronous' in the current version.",
"(ChangedParameterOrdering): The class 'QueueClient' method 'from_connection_string' had its parameters re-ordered from '['conn_str', 'queue_name', 'credential', 'kwargs']' to '['queue_name', 'conn_str', 'credential', 'kwargs']' in the current version",
"(ChangedParameterOrdering): The class 'QueueClient' method 'from_connection_string' had its parameters re-ordered from '['conn_str', 'queue_name', 'credential', 'kwargs']' to '['queue_name', 'conn_str', 'credential', 'kwargs']' in the current version",
]


Expand Down Expand Up @@ -183,10 +183,10 @@ def test_replace_all_params():
}

EXPECTED = [
"(RemovedOrRenamedPositionalParam): The 'azure.ai.formrecognizer.class_name' method 'one' had its parameter 'testing' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(RemovedOrRenamedPositionalParam): The 'azure.ai.formrecognizer.class_name' method 'two' had its parameter 'testing2' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(RemovedOrRenamedPositionalParam): The function 'azure.ai.formrecognizer.my_function_name' had its parameter 'testing' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(RemovedOrRenamedPositionalParam): The function 'azure.ai.formrecognizer.my_function_name' had its parameter 'testing2' of kind 'positional_or_keyword' deleted or renamed in the current version"
"(RemovedOrRenamedPositionalParam): The 'class_name' method 'one' had its parameter 'testing' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(RemovedOrRenamedPositionalParam): The 'class_name' method 'two' had its parameter 'testing2' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(RemovedOrRenamedPositionalParam): The function 'my_function_name' had its parameter 'testing' of kind 'positional_or_keyword' deleted or renamed in the current version",
"(RemovedOrRenamedPositionalParam): The function 'my_function_name' had its parameter 'testing2' of kind 'positional_or_keyword' deleted or renamed in the current version"
]

diff = jsondiff.diff(stable, current)
Expand Down Expand Up @@ -271,10 +271,10 @@ def test_replace_all_functions():
}

EXPECTED = [
"(RemovedOrRenamedClassMethod): The 'azure.ai.formrecognizer.class_name' method 'one' was deleted or renamed in the current version",
"(RemovedOrRenamedClassMethod): The 'azure.ai.formrecognizer.class_name' method 'two' was deleted or renamed in the current version",
"(RemovedOrRenamedModuleLevelFunction): The publicly exposed function 'azure.ai.formrecognizer.my_function_name' was deleted or renamed in the current version",
"(RemovedOrRenamedModuleLevelFunction): The publicly exposed function 'azure.ai.formrecognizer.my_function_name2' was deleted or renamed in the current version"
"(RemovedOrRenamedClassMethod): The 'class_name' method 'one' was deleted or renamed in the current version",
"(RemovedOrRenamedClassMethod): The 'class_name' method 'two' was deleted or renamed in the current version",
"(RemovedOrRenamedModuleLevelFunction): The publicly exposed function 'my_function_name' was deleted or renamed in the current version",
"(RemovedOrRenamedModuleLevelFunction): The publicly exposed function 'my_function_name2' was deleted or renamed in the current version"
]

diff = jsondiff.diff(stable, current)
Expand Down Expand Up @@ -347,8 +347,8 @@ def test_replace_all_classes():
}

EXPECTED = [
"(RemovedOrRenamedClass): The model or publicly exposed class 'azure.ai.formrecognizer.class_name' was deleted or renamed in the current version",
"(RemovedOrRenamedClass): The model or publicly exposed class 'azure.ai.formrecognizer.class_name2' was deleted or renamed in the current version"
"(RemovedOrRenamedClass): The model or publicly exposed class 'class_name' was deleted or renamed in the current version",
"(RemovedOrRenamedClass): The model or publicly exposed class 'class_name2' was deleted or renamed in the current version"
]

diff = jsondiff.diff(stable, current)
Expand Down Expand Up @@ -433,7 +433,7 @@ def test_removed_operation_group():
}

EXPECTED = [
"(RemovedOrRenamedOperationGroup): The 'azure.contoso.ContosoClient' client had operation group 'foo' deleted or renamed in the current version"
"(RemovedOrRenamedOperationGroup): The 'ContosoClient' client had operation group 'foo' deleted or renamed in the current version"
]

diff = jsondiff.diff(stable, current)
Expand Down