Skip to content

COUNTRIES_FIRST modifies max_length for CountryField(multiple=True) #469

@cnschn

Description

@cnschn

There is a small bug in the calculation of max_length in CountryField when multiple=True:

kwargs["max_length"] = (
    len(self.countries)
    - 1
    + sum(len(code) for code in self.countries.countries)
)

I guess this is supposed to encode "Everything is selected" (the sum()) + "N-1 commas in between" (the len() - 1). However while self.countries.countries correctly lists all the possible countries, self.countries (i.e. Countries.__iter__!) emits the COUNTRIES_FIRST as well, so those are counted multiple times!

The fix will probably just be to replace len(self.countries) with len(self.countries.countries) here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions