-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Hard-deleting a subject fails if the subject has already been soft-deleted #1127
Comments
RemediationOption 1Perform only 1 request depending on the value of permanent. def delete_subject(self, subject_name, permanent=False):
"""
Deletes the specified subject and its associated compatibility level if
registered. It is recommended to use this API only when a topic needs
to be recycled or in development environments.
Args:
subject_name (str): subject name
permanent (bool): True for a hard delete, False (default) for a soft delete
Returns:
list(int): Versions deleted under this subject
Raises:
SchemaRegistryError: if the request was unsuccessful.
See Also:
`DELETE Subject API Reference <https://docs.confluent.io/current/schema-registry/develop/api.html#delete--subjects-(string-%20subject)>`_
""" # noqa: E501
if permanent:
return self._rest_client.delete('subjects/{}?permanent=true'
.format(_urlencode(subject_name)))
return self._rest_client.delete('subjects/{}'
.format(_urlencode(subject_name))) Pros:
Cons:
Option 2Keep the routine but wrap the soft-delete call to catch 404 def delete_subject(self, subject_name, permanent=False):
"""
Deletes the specified subject and its associated compatibility level if
registered. It is recommended to use this API only when a topic needs
to be recycled or in development environments.
Args:
subject_name (str): subject name
permanent (bool): True for a hard delete, False (default) for a soft delete
Returns:
list(int): Versions deleted under this subject
Raises:
SchemaRegistryError: if the request was unsuccessful.
See Also:
`DELETE Subject API Reference <https://docs.confluent.io/current/schema-registry/develop/api.html#delete--subjects-(string-%20subject)>`_
""" # noqa: E501
try:
list = self._rest_client.delete('subjects/{}'
.format(_urlencode(subject_name)))
except SchemaRegistryError as e:
if e.http_status_code != 404:
raise
if permanent:
list = self._rest_client.delete('subjects/{}?permanent=true'
.format(_urlencode(subject_name)))
return list Pros:
Cons:
|
Related to #1029 @slominskir |
I’m not sure which is the best approach. I find the distinction between soft and hard delete dubious so I just hard delete everything, but we should support all combinations - forcing a two step process may better match the REST API so I guess I’m leaning that way and catching exceptions inside the method can potentially hide issues (404 might occur for some other reason - maybe misconfigured registry url) |
Right, for the SchemaRegistryError object, we can opt for error_code instead of http_status_code. confluent_kafka.schema_registry.error.SchemaRegistryError: Subject 'lorem-ipsum-value' was soft deleted.Set permanent=true to delete permanently (HTTP status code 404, SR code 40404) def delete_subject(self, subject_name, permanent=False):
"""
Deletes the specified subject and its associated compatibility level if
registered. It is recommended to use this API only when a topic needs
to be recycled or in development environments.
Args:
subject_name (str): subject name
permanent (bool): True for a hard delete, False (default) for a soft delete
Returns:
list(int): Versions deleted under this subject
Raises:
SchemaRegistryError: if the request was unsuccessful.
See Also:
`DELETE Subject API Reference <https://docs.confluent.io/current/schema-registry/develop/api.html#delete--subjects-(string-%20subject)>`_
""" # noqa: E501
try:
list = self._rest_client.delete('subjects/{}'
.format(_urlencode(subject_name)))
except SchemaRegistryError as e:
if e.error_code != 40404:
raise
if permanent:
list = self._rest_client.delete('subjects/{}?permanent=true'
.format(_urlencode(subject_name)))
return list |
Looks good to me. Submit that change as a pull request and see if maintainers go for it. |
@PatrickTu I was wondering if you are still experiencing this issue in the latest versions, or if it has been solved in any of the updates since then |
Fixed by #1867 |
Description
Attempting to hard-delete a subject that has been soft-deleted ends up throwing a 404 error and will never execute the hard-delete API call.
How to reproduce
Schema Registry returns the follow error
Repro Script
Checklist
Please provide the following information:
confluent-kafka-python and librdkafka version (
confluent_kafka.version()
andconfluent_kafka.libversion()
):confluent-kafka-python = ('1.6.1', 17170688)
Librdkafka = ('1.6.1', 17170943)
Apache Kafka broker version:
Client configuration:
{...}
Operating system: macOS Catalina (10.15.7)
Provide client logs (with
'debug': '..'
as necessary)Provide broker log excerpts
Critical issue
The text was updated successfully, but these errors were encountered: