codeant-ai-for-open-source[bot] commented on code in PR #45790: URL: https://github.com/apache/superset/pull/45790#discussion_r4390435247
########## superset/migrations/versions/2026-10-27_00-00_9670ab7f6bc6_normalize_metadata_cache_timeouts.py: ########## @@ -0,0 +1,89 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Normalize legacy database metadata cache timeouts. + +Older database forms stored metadata cache timeouts as strings. Convert only +recognized non-negative integer strings, preserving malformed configurations +and unrelated fields instead of guessing at their intended values. + +Revision ID: 9670ab7f6bc6 +Revises: d623a0cb6bb0 +Create Date: 2026-10-27 00:00:00.000000 +""" + +# The shared JSON wrapper cannot decode decimals without losing stored precision. +import simplejson # noqa: TID251 +from alembic import op +from sqlalchemy import column, Integer, select, table, Text + +from superset.utils import json + +revision = "9670ab7f6bc6" +down_revision = "d623a0cb6bb0" + +_DATABASES = table("dbs", column("id", Integer), column("extra", Text)) +_TIMEOUT_KEYS = ( + "catalog_cache_timeout", + "schema_cache_timeout", + "table_cache_timeout", +) + + +def upgrade() -> None: + """Convert legacy non-negative integer strings to integer timeouts.""" + connection = op.get_bind() + for database_id, raw_extra in connection.execute( + select(_DATABASES.c.id, _DATABASES.c.extra) + ): + try: + extra = simplejson.loads(raw_extra, use_decimal=True) + except (TypeError, ValueError): + continue + if not isinstance(extra, dict): + continue + timeouts = extra.get("metadata_cache_timeout") + if not isinstance(timeouts, dict): + continue + + changed = False + for key in _TIMEOUT_KEYS: + value = timeouts.get(key) + if not isinstance(value, str): + continue + try: + timeout = int(value) + except ValueError: + continue + if timeout < 0: + continue + timeouts[key] = timeout + changed = True + + if changed: + connection.execute( + _DATABASES.update() + .where(_DATABASES.c.id == database_id) + .values(extra=json.dumps(extra)) Review Comment: **Suggestion:** A concurrent edit to `dbs.extra` after the SELECT can be overwritten by this stale snapshot, losing the newer configuration. **Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Race condition` [](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0ed330bc150a4eafa7520f31400efffb&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0ed330bc150a4eafa7520f31400efffb&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/migrations/versions/2026-10-27_00-00_9670ab7f6bc6_normalize_metadata_cache_timeouts.py **Line:** 77:80 **Comment:** *Race Condition: A concurrent edit to `dbs.extra` after the SELECT can be overwritten by this stale snapshot, losing the newer configuration. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45790&comment_hash=a04684158231f2a66de42de52ca263f3c744737ba935824959ec14b9761d753b&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45790&comment_hash=a04684158231f2a66de42de52ca263f3c744737ba935824959ec14b9761d753b&reaction=dislike'>๐</a> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
