Skip to content

cli: fix partitions delete-records with --format json - #3213

Open
LemonCondor wants to merge 1 commit into
dpkp:masterfrom
LemonCondor:fix/cli-delete-records-json
Open

LemonCondor wants to merge 1 commit into
dpkp:masterfrom
LemonCondor:fix/cli-delete-records-json

Conversation

@LemonCondor

Copy link
Copy Markdown

python -m kafka.admin ... --format json partitions delete-records deletes the records, then prints a traceback and exits 1 (output of kafka.cli.admin.run_cli() against the test MockBroker):

$ python -m kafka.admin -b localhost:9092 --format json partitions delete-records -r topic-a:0:10
CRITICAL:kafka.cli.admin:Error!
Traceback (most recent call last):
  File "kafka/cli/admin/__init__.py", line 83, in run_cli
    print(json.dumps(result))
  ...
TypeError: keys must be str, int, float, bool or None, not TopicPartition

A script that checks the exit code will believe the deletion failed.

delete_records() returns a dict keyed by TopicPartition. The command now keys its output by "topic:partition", as list-reassignments, alter-reassignments and the group offset commands already do. The KafkaAdminClient.delete_records() return value is unchanged. The default raw output changes too: its keys are now the same strings instead of TopicPartition(...).

Test: added TestDeleteRecordsCli in test/admin/test_admin_partitions.py. It fails on master with the TypeError above and passes with the change. pytest test/admin passes (204 tests, MockBroker only, no real cluster), and pylint --errors-only on kafka/cli and the test file reports nothing.

delete_records() returns a dict keyed by TopicPartition, which json.dumps()
rejects. The records were deleted, but the command then printed a traceback
and exited 1. Key the CLI output by "topic:partition", as the other
partition and group offset commands do.
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