Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cnschn opened this issue Sep 4, 2024 · 0 comments · May be fixed by #470
Open

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

cnschn opened this issue Sep 4, 2024 · 0 comments · May be fixed by #470

Comments

@cnschn
Copy link

cnschn commented Sep 4, 2024

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.

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 a pull request may close this issue.

1 participant