Skip to content

Commit

Permalink
feat: allow feature value size to be configured per installation (#4446)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Elwell <[email protected]>
  • Loading branch information
rolodato and matthewelwell authored Sep 27, 2024
1 parent bc77fb0 commit c28f6f1
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,12 @@
"SEGMENT_CONDITION_VALUE_LIMIT must be between 0 and 2,000,000 (2MB)."
)

FEATURE_VALUE_LIMIT = env.int("FEATURE_VALUE_LIMIT", default=20_000)
if not 0 <= FEATURE_VALUE_LIMIT <= 2000000: # pragma: no cover
raise ImproperlyConfigured(
"FEATURE_VALUE_LIMIT must be between 0 and 2,000,000 (2MB)."
)

SEGMENT_RULES_CONDITIONS_LIMIT = env.int("SEGMENT_RULES_CONDITIONS_LIMIT", 100)

WEBHOOK_BACKOFF_BASE = env.int("WEBHOOK_BACKOFF_BASE", default=2)
Expand Down
5 changes: 4 additions & 1 deletion api/features/feature_states/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing

from django.conf import settings
from django.db import models

from features.value_types import (
Expand All @@ -23,7 +24,9 @@ class Meta:
)
boolean_value = models.BooleanField(null=True, blank=True)
integer_value = models.IntegerField(null=True, blank=True)
string_value = models.CharField(null=True, max_length=20000, blank=True)
string_value = models.CharField(
null=True, max_length=settings.FEATURE_VALUE_LIMIT, blank=True
)

@property
def value(self) -> typing.Union[str, int, bool]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.25 on 2024-08-01 21:09
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('features', '0064_fix_feature_help_text_typo'),
]

operations = [
migrations.AlterField(
model_name='feature',
name='initial_value',
field=models.CharField(blank=True, max_length=settings.FEATURE_VALUE_LIMIT, null=True, default=None),
),
migrations.AlterField(
model_name='historicalfeature',
name='initial_value',
field=models.CharField(blank=True, max_length=settings.FEATURE_VALUE_LIMIT, null=True, default=None),
),
migrations.AlterField(
model_name='featurestatevalue',
name='string_value',
field=models.CharField(blank=True, max_length=settings.FEATURE_VALUE_LIMIT, null=True),
),
migrations.AlterField(
model_name='historicalfeaturestatevalue',
name='string_value',
field=models.CharField(blank=True, max_length=settings.FEATURE_VALUE_LIMIT, null=True),
),
]
3 changes: 2 additions & 1 deletion api/features/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SoftDeleteExportableModel,
abstract_base_auditable_model_factory,
)
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation
from django.core.exceptions import (
NON_FIELD_ERRORS,
Expand Down Expand Up @@ -109,7 +110,7 @@ class Feature(
on_delete=models.DO_NOTHING,
)
initial_value = models.CharField(
max_length=20000, null=True, default=None, blank=True
max_length=settings.FEATURE_VALUE_LIMIT, null=True, default=None, blank=True
)
description = models.TextField(null=True, blank=True)
default_enabled = models.BooleanField(default=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.25 on 2024-08-01 21:09
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('multivariate', '0007_alter_boolean_values'),
]

operations = [
migrations.AlterField(
model_name='historicalmultivariatefeatureoption',
name='string_value',
field=models.CharField(blank=True, max_length=settings.FEATURE_VALUE_LIMIT, null=True),
),
migrations.AlterField(
model_name='multivariatefeatureoption',
name='string_value',
field=models.CharField(blank=True, max_length=settings.FEATURE_VALUE_LIMIT, null=True),
),
]

0 comments on commit c28f6f1

Please sign in to comment.