Features: 1) Implement safeguard to trim resolving_name exceeding 255 characters; 2) Introduce character limit enforcement for key within Attribute creation;

Fixes: 1) None;

Extra: Refactor handling of oversized strings to improve robustness and avoid potential errors;
This commit is contained in:
Egor Pavlovich Gorbunov 2025-07-02 17:28:05 +03:00
parent 81675fc55f
commit d17839abed

View file

@ -148,6 +148,8 @@ class AbstractVendor:
def auto_resolver_helper(model: Brand | Category, resolving_name: str) -> Brand | Category | None:
queryset = model.objects.filter(name=resolving_name)
if not queryset.exists():
if len(resolving_name) > 255:
resolving_name = resolving_name[:255]
return model.objects.get_or_create(name=resolving_name, defaults={"is_active": False})[0]
elif queryset.filter(is_active=True).count() > 1:
queryset = queryset.filter(is_active=True)
@ -326,6 +328,9 @@ class AbstractVendor:
is_created = False
if len(key) > 255:
key = key[:255]
try:
attribute, is_created = Attribute.objects.get_or_create(
name=key,