Skip to content

Commit 8f01e64

Browse files
committed
Add allow_null_values to target column config
1 parent 64f6c26 commit 8f01e64

File tree

8 files changed

+188
-119
lines changed

8 files changed

+188
-119
lines changed

app/blueprints/docs/surveystream.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,9 +3687,9 @@ paths:
36873687
description: >-
36883688
The field type of the column. Can be one of
36893689
`personal_details`, `custom_field`, or `location`.
3690-
bulk_editable:
3690+
allow_null_values:
36913691
type: boolean
3692-
description: Whether the field is bulk editable or not
3692+
description: Whether the field allows null values or not
36933693
column_source:
36943694
type: string
36953695
description: >-
@@ -3698,7 +3698,6 @@ paths:
36983698
required:
36993699
- column_name
37003700
- column_type
3701-
- bulk_editable
37023701
- column_source
37033702
required:
37043703
- form_uid
@@ -3757,9 +3756,9 @@ paths:
37573756
description: >
37583757
The field type of the column. Can be one of
37593758
`personal_details`, `custom_field`, or `location`.
3760-
bulk_editable:
3759+
allow_null_values:
37613760
type: boolean
3762-
description: Whether the field is bulk editable or not.
3761+
description: Whether the field allows null values or not.
37633762
column_source:
37643763
type: string
37653764
description: >-
@@ -7382,13 +7381,12 @@ paths:
73827381
description: >-
73837382
The field type of the column. Can be one of
73847383
`basic_details`, `custom_field`, or `location`.
7385-
bulk_editable:
7384+
allow_null_values:
73867385
type: boolean
7387-
description: Whether the field is bulk editable or not
7386+
description: Whether the field allows null values or not
73887387
required:
73897388
- column_name
73907389
- column_type
7391-
- bulk_editable
73927390
filters:
73937391
type: array
73947392
description: >-
@@ -7459,9 +7457,9 @@ paths:
74597457
items:
74607458
type: object
74617459
properties:
7462-
bulk_editable:
7460+
allow_null_values:
74637461
type: boolean
7464-
description: Whether the field is bulk editable or not.
7462+
description: Whether the field allows null values or not.
74657463
column_name:
74667464
type: string
74677465
description: The field name of the column.

app/blueprints/locations/controllers.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,25 @@ def append_locations(validated_query_params, validated_payload):
10421042
),
10431043
422,
10441044
)
1045+
except Exception as e:
1046+
return (
1047+
jsonify(
1048+
{
1049+
"success": False,
1050+
"record_errors": {
1051+
"summary_by_error_type": [
1052+
{
1053+
"error_type": "File processing error",
1054+
"error_message": str(e),
1055+
"error_count": 1,
1056+
"row_numbers_with_errors": [],
1057+
}
1058+
]
1059+
},
1060+
}
1061+
),
1062+
422,
1063+
)
10451064

10461065
# Get the existing locations for the survey
10471066

@@ -1126,6 +1145,25 @@ def append_locations(validated_query_params, validated_payload):
11261145
),
11271146
422,
11281147
)
1148+
except Exception as e:
1149+
return (
1150+
jsonify(
1151+
{
1152+
"success": False,
1153+
"record_errors": {
1154+
"summary_by_error_type": [
1155+
{
1156+
"error_type": "File processing error",
1157+
"error_message": str(e),
1158+
"error_count": 1,
1159+
"row_numbers_with_errors": [],
1160+
}
1161+
]
1162+
},
1163+
}
1164+
),
1165+
422,
1166+
)
11291167

11301168
for i, geo_level in enumerate(geo_level_hierarchy.ordered_geo_levels):
11311169
# Get the location_id and location_name column names for the geo level

app/blueprints/targets/controllers.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,9 @@ def bulk_update_targets(validated_payload):
10081008
"location": [],
10091009
"custom_fields": [],
10101010
}
1011-
10121011
for column in column_config:
1013-
if column.bulk_editable:
1012+
# Skip target_id column as it shouldn't be bulk editable
1013+
if column.column_name != "target_id":
10141014
bulk_editable_fields[column.column_type].append(column.column_name)
10151015

10161016
for key in payload.keys():
@@ -1174,16 +1174,6 @@ def update_target_column_config(validated_payload):
11741174
db.session.flush()
11751175

11761176
for column in payload["column_config"]:
1177-
if not isinstance(column["bulk_editable"], bool):
1178-
return (
1179-
jsonify(
1180-
{
1181-
"success": False,
1182-
"errors": f"Field 'bulk_editable' must be a boolean",
1183-
}
1184-
),
1185-
422,
1186-
)
11871177
if not isinstance(column["contains_pii"], bool):
11881178
return (
11891179
jsonify(
@@ -1200,7 +1190,7 @@ def update_target_column_config(validated_payload):
12001190
form_uid=form_uid,
12011191
column_name=column["column_name"],
12021192
column_type=column["column_type"],
1203-
bulk_editable=column["bulk_editable"],
1193+
allow_null_values=column["allow_null_values"],
12041194
contains_pii=column["contains_pii"],
12051195
column_source=column["column_source"],
12061196
)
@@ -1254,7 +1244,7 @@ def get_target_column_config(validated_query_params):
12541244
{
12551245
"column_name": column.column_name,
12561246
"column_type": column.column_type,
1257-
"bulk_editable": column.bulk_editable,
1247+
"allow_null_values": column.allow_null_values,
12581248
"contains_pii": column.contains_pii,
12591249
"column_source": column.column_source,
12601250
}

app/blueprints/targets/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class TargetColumnConfig(db.Model):
152152
),
153153
nullable=False,
154154
)
155-
bulk_editable = db.Column(db.Boolean(), nullable=False, default=False)
155+
allow_null_values = db.Column(db.Boolean(), nullable=False, server_default="true")
156156
contains_pii = db.Column(db.Boolean(), nullable=True)
157157
column_source = db.Column(
158158
db.String(),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Targets Column Config : Add allow_null_values column, remove bulk_editable column
3+
4+
Revision ID: b0c4574bd52e
5+
Revises: c5530d333545
6+
Create Date: 2025-07-17 07:14:01.333110
7+
8+
"""
9+
10+
import sqlalchemy as sa
11+
from alembic import op
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "b0c4574bd52e"
15+
down_revision = "c5530d333545"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
with op.batch_alter_table("target_column_config", schema="webapp") as batch_op:
23+
batch_op.add_column(
24+
sa.Column(
25+
"allow_null_values", sa.Boolean(), server_default="true", nullable=False
26+
)
27+
)
28+
batch_op.drop_column("bulk_editable")
29+
30+
# ### end Alembic commands ###
31+
32+
33+
def downgrade():
34+
# ### commands auto generated by Alembic - please adjust! ###
35+
with op.batch_alter_table("target_column_config", schema="webapp") as batch_op:
36+
batch_op.add_column(
37+
sa.Column(
38+
"bulk_editable", sa.BOOLEAN(), autoincrement=False, nullable=False
39+
)
40+
)
41+
batch_op.drop_column("allow_null_values")
42+
43+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)