Skip to content

Commit 9f20479

Browse files
hughcapetavandras
authored andcommitted
Make sure str representation is used for click options (patroni#3352)
The previous version only worked before the click-8.2 token-normalization changes
1 parent 2d10c10 commit 9f20479

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

patroni/ctl.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ def parse_scheduled(scheduled: Optional[str]) -> Optional[datetime.datetime]:
10531053
@click.argument('member_names', nargs=-1)
10541054
@option_citus_group
10551055
@click.option('--role', '-r', help='Reload only members with this role',
1056-
type=role_choice, default=CtlPostgresqlRole.ANY)
1056+
type=role_choice, default=repr(CtlPostgresqlRole.ANY))
10571057
@option_force
10581058
def reload(cluster_name: str, member_names: List[str], group: Optional[int],
10591059
force: bool, role: CtlPostgresqlRole) -> None:
@@ -1092,7 +1092,7 @@ def reload(cluster_name: str, member_names: List[str], group: Optional[int],
10921092
@click.argument('member_names', nargs=-1)
10931093
@option_citus_group
10941094
@click.option('--role', '-r', help='Restart only members with this role', type=role_choice,
1095-
default=CtlPostgresqlRole.ANY)
1095+
default=repr(CtlPostgresqlRole.ANY))
10961096
@click.option('--any', 'p_any', help='Restart a single member only', is_flag=True)
10971097
@click.option('--scheduled', help='Timestamp of a scheduled restart in unambiguous format (e.g. ISO 8601)',
10981098
default=None)
@@ -1924,7 +1924,8 @@ def timestamp(precision: int = 6) -> str:
19241924
@option_citus_group
19251925
@click.argument('member_names', nargs=-1)
19261926
@click.argument('target', type=click.Choice(['restart', 'switchover']))
1927-
@click.option('--role', '-r', help='Flush only members with this role', type=role_choice, default=CtlPostgresqlRole.ANY)
1927+
@click.option('--role', '-r', help='Flush only members with this role',
1928+
type=role_choice, default=repr(CtlPostgresqlRole.ANY))
19281929
@option_force
19291930
def flush(cluster_name: str, group: Optional[int],
19301931
member_names: List[str], force: bool, role: CtlPostgresqlRole, target: str) -> None:

tests/test_ctl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def test_get_dcs(self):
270270
def test_query(self):
271271
# Mutually exclusive
272272
for role in self.TEST_ROLES:
273-
result = self.runner.invoke(ctl, ['query', 'alpha', '--member', 'abc', '--role', role])
273+
result = self.runner.invoke(ctl, ['query', 'alpha', '--member', 'abc', '--role', repr(role)])
274274
assert result.exit_code == 1
275275

276276
with self.runner.isolated_filesystem():
@@ -331,7 +331,7 @@ def test_dsn(self):
331331

332332
# Mutually exclusive options
333333
for role in self.TEST_ROLES:
334-
result = self.runner.invoke(ctl, ['dsn', 'alpha', '--role', role, '--member', 'dummy'])
334+
result = self.runner.invoke(ctl, ['dsn', 'alpha', '--role', repr(role), '--member', 'dummy'])
335335
assert result.exit_code == 1
336336

337337
# Non-existing member
@@ -555,7 +555,7 @@ def test_topology(self):
555555
@patch('patroni.dcs.AbstractDCS.get_cluster', Mock(return_value=get_cluster_initialized_with_leader()))
556556
def test_flush_restart(self):
557557
for role in self.TEST_ROLES:
558-
result = self.runner.invoke(ctl, ['flush', 'dummy', 'restart', '-r', role], input='y')
558+
result = self.runner.invoke(ctl, ['flush', 'dummy', 'restart', '-r', repr(role)], input='y')
559559
assert 'No scheduled restart' in result.output
560560

561561
result = self.runner.invoke(ctl, ['flush', 'dummy', 'restart', '--force'])

0 commit comments

Comments
 (0)