From 3f4f9d98de1c86b6d64d001a95abdb25c68f7c43 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 9 Sep 2020 20:46:24 +0200 Subject: [PATCH] Increase length of multiple-choice country fields --- src/pretix/helpers/countries.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pretix/helpers/countries.py b/src/pretix/helpers/countries.py index 4799d68249..2afdc5f94b 100644 --- a/src/pretix/helpers/countries.py +++ b/src/pretix/helpers/countries.py @@ -33,6 +33,15 @@ class CachedCountries(Countries): class FastCountryField(CountryField): def __init__(self, *args, **kwargs): kwargs.setdefault("countries", CachedCountries) + + if "max_length" not in kwargs: + # Override logic from CountryField to include 20% buffer. We don't want to migrate our database + # every time a new country is added to the system! + if kwargs.get("multiple", False): + kwargs["max_length"] = int(len(kwargs['countries']()) * 3 * 1.2) + else: + kwargs["max_length"] = 2 + super().__init__(*args, **kwargs) def check(self, **kwargs):