Skip to content

Commit b8c9aa0

Browse files
ekanshulclaude
andcommitted
Check for NULL instead of matching a numeric pattern
The crash this fixes is a widget with no position values, so a NULL check is enough to skip those rows. The numeric pattern also skipped values that are not base-10 integers, which the original statement did not do. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 9ea7983 commit b8c9aa0

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

migrations/versions/db0aca1ebd32_12_column_dashboard_layout.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@
1717

1818

1919
def upgrade():
20-
# Skip widgets whose position values are missing or not numeric, e.g. rows
21-
# written through the API with options = '{}'. Without the filter the cast
22-
# yields NULL, jsonb_set() returns NULL for a NULL new_value, and the update
23-
# fails the NOT NULL constraint on widgets.options.
20+
# Skip widgets that have no position values, e.g. rows written through the
21+
# API with options = '{}'. Without the filter the cast yields NULL,
22+
# jsonb_set() returns NULL for a NULL new_value, and the update fails the
23+
# NOT NULL constraint on widgets.options.
2424
op.execute("""
2525
UPDATE widgets
2626
SET options = jsonb_set(options, '{position,col}', to_json((options->'position'->>'col')::int * 2)::jsonb)
27-
WHERE options->'position'->>'col' ~ '^-?[0-9]+$';
27+
WHERE options->'position'->>'col' IS NOT NULL;
2828
UPDATE widgets
2929
SET options = jsonb_set(options, '{position,sizeX}', to_json((options->'position'->>'sizeX')::int * 2)::jsonb)
30-
WHERE options->'position'->>'sizeX' ~ '^-?[0-9]+$';
30+
WHERE options->'position'->>'sizeX' IS NOT NULL;
3131
""")
3232

3333

3434
def downgrade():
3535
op.execute("""
3636
UPDATE widgets
3737
SET options = jsonb_set(options, '{position,col}', to_json((options->'position'->>'col')::int / 2)::jsonb)
38-
WHERE options->'position'->>'col' ~ '^-?[0-9]+$';
38+
WHERE options->'position'->>'col' IS NOT NULL;
3939
UPDATE widgets
4040
SET options = jsonb_set(options, '{position,sizeX}', to_json((options->'position'->>'sizeX')::int / 2)::jsonb)
41-
WHERE options->'position'->>'sizeX' ~ '^-?[0-9]+$';
41+
WHERE options->'position'->>'sizeX' IS NOT NULL;
4242
""")

0 commit comments

Comments
 (0)