Opened 3 months ago

Closed 3 months ago

#35689 closed Bug (fixed)

`LabelCommand`: `label` does not affect the `missing_args_message`

Reported by: Kamil Paduszyński Owned by: Giovanni Fabbretti
Component: Core (Management commands) Version: 5.1
Severity: Normal Keywords:
Cc: Kamil Paduszyński Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The missing_args_message attribute of the django.core.management.base.LabelCommand is hard coded using the default value of label = "label".

I would suggest the following update:

class LabelCommand(BaseCommand):
    label = "label"
    missing_args_message = "Enter at least one %s."

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        
        self.missing_args_message = (
            (missing_args_message % self.label)
            if (missing_args_message := self.missing_args_message) is not None
            else None
        ) 

Of course, I am open to refactoring - a single, complex though, conditional assignment allows for avoiding branching.

It can be tested by updating the test_label_command_no_label case.

Change History (7)

comment:1 by Sarah Boyce, 3 months ago

Triage Stage: UnreviewedAccepted

Thank you!
Replicated - example failing test

  • tests/staticfiles_tests/test_management.py

    a b class TestFindStatic(TestDefaults, CollectionTestCase):  
    124124            searched_locations,
    125125        )
    126126
     127    def test_missing_args_message(self):
     128        msg = "Enter at least one staticfile."
     129        with self.assertRaisesMessage(CommandError, msg):
     130            call_command("findstatic")
     131

Would you like to submit a PR?

comment:2 by Giovanni Fabbretti, 3 months ago

Owner: set to Giovanni Fabbretti
Status: newassigned

comment:3 by Giovanni Fabbretti, 3 months ago

Has patch: set

Hello,
I have created a PR implementing the test proposed by Sarah and the solution proposed by Kamil.

comment:4 by Sarah Boyce, 3 months ago

Triage Stage: AcceptedReady for checkin

comment:5 by Sarah Boyce, 3 months ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:6 by Sarah Boyce, 3 months ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:7 by Sarah Boyce <42296566+sarahboyce@…>, 3 months ago

Resolution: fixed
Status: assignedclosed

In f72bbd44:

Fixed #35689 -- Handled custom labels in LabelCommand.missing_args_message.

Note: See TracTickets for help on using tickets.
Back to Top