codeant-ai-for-open-source[bot] commented on code in PR #39469:
URL: https://github.com/apache/superset/pull/39469#discussion_r3442973649


##########
superset/migrations/versions/2026-05-13_12-00_c6219cac9270_add_user_session_auth_stamp_table.py:
##########
@@ -0,0 +1,52 @@
+# 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.
+"""add user_session_auth_stamp table
+
+Revision ID: c6219cac9270
+Revises: b7e4f2a891c3
+Create Date: 2026-05-13 12:00:00.000000
+
+"""
+
+import sqlalchemy as sa
+
+from superset.migrations.shared.utils import create_table, drop_table
+
+# revision identifiers, used by Alembic.
+revision = "c6219cac9270"
+down_revision = "b7e4f2a891c3"

Review Comment:
   **Suggestion:** The migration references a `down_revision` that does not 
exist in this repository, so Alembic cannot build the revision graph and 
upgrades will fail with a missing-revision error. Point `down_revision` to an 
actual existing predecessor revision ID. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ `superset db upgrade` fails with Alembic missing revision error.
   - ❌ App initialization stops before sync_config_to_db runs successfully.
   - ⚠️ Pending migrations prevent new features relying on this table.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Inspect the new migration file
   
`superset/migrations/versions/2026-05-13_12-00_c6219cac9270_add_user_session_auth_stamp_table.py`,
   where the Alembic identifiers are defined (`revision = "c6219cac9270"` and 
`down_revision
   = "b7e4f2a891c3"` at lines 29–31, confirmed via Read).
   
   2. List and search all existing migration scripts under 
`superset/migrations/versions/`
   (as in the LS output and a Grep for `b7e4f2a891c3`); note that no file name 
or file
   content in this directory defines `revision = "b7e4f2a891c3"`, meaning this 
parent
   revision does not exist in the current repository.
   
   3. Start Superset so that initialization runs 
`self.superset_app.sync_config_to_db()` from
   `superset/initialization/__init__.py:635`, which calls 
`_is_database_up_to_date()` in
   `superset/app.py:119-129`; this method builds an Alembic `ScriptDirectory` 
with
   `script_location="superset:migrations"` and calls 
`script.get_current_head()`, forcing
   Alembic to load the revision graph from `superset/migrations/versions/`.
   
   4. When Alembic processes the new migration with `revision = "c6219cac9270"` 
and
   `down_revision = "b7e4f2a891c3"` (lines 29–31 of the migration file), it 
cannot find a
   revision with ID `b7e4f2a891c3` in the script directory, causing a 
missing-revision error
   while building the revision graph; `_is_database_up_to_date()` catches the 
resulting
   exception and returns `False`, so `sync_config_to_db()` logs "Pending 
database migrations:
   run 'superset db upgrade'" at `superset/app.py:168`, and any attempt to 
actually run
   `superset db upgrade` (using the Alembic environment in
   `superset/migrations/env.py:64-85,87-137`) will also fail with an Alembic 
"no such
   revision b7e4f2a891c3" error.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=514e5448ddbc4076ad88c3fc6114ef04&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=514e5448ddbc4076ad88c3fc6114ef04&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset/migrations/versions/2026-05-13_12-00_c6219cac9270_add_user_session_auth_stamp_table.py
   **Line:** 31:31
   **Comment:**
        *Api Mismatch: The migration references a `down_revision` that does not 
exist in this repository, so Alembic cannot build the revision graph and 
upgrades will fail with a missing-revision error. Point `down_revision` to an 
actual existing predecessor revision ID.
   
   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%2F39469&comment_hash=501bbb9f909d8b3b90493a801a5c9612bc1f4d5ff60be8515336137d04fd6237&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39469&comment_hash=501bbb9f909d8b3b90493a801a5c9612bc1f4d5ff60be8515336137d04fd6237&reaction=dislike'>👎</a>



##########
superset-frontend/src/features/users/utils.ts:
##########
@@ -19,8 +19,34 @@
 import { t } from '@apache-superset/core/translation';
 import { SupersetClient } from '@superset-ui/core';
 import { SelectOption } from 'src/components/ListView';
+import type { UserObject } from 'src/pages/UsersList/types';
 import { FormValues } from './types';
 
+/** Fields required for PUT `/api/v1/security/users/:id` when changing 
password only. */
+export function buildSecurityUserUpdatePayload(user: UserObject): FormValues {
+  return {
+    first_name: user.first_name,
+    last_name: user.last_name,
+    username: user.username,
+    email: user.email,
+    active: user.active,
+    roles: (user.roles ?? []).map(r => r.id),
+    groups: (user.groups ?? []).map(g => g.id),
+  };
+}
+
+export const resetUserPassword = async (
+  userId: number,
+  password: string,
+): Promise<void> => {
+  await SupersetClient.put({
+    endpoint: `/api/v1/security/users/${userId}`,
+    jsonPayload: {
+      password,
+    },
+  });
+};

Review Comment:
   **Suggestion:** The admin reset-password request sends only `password` to 
`PUT /api/v1/security/users/:id`, but this endpoint expects the full user 
update payload in this codebase flow. As written, password resets can fail with 
validation errors (or overwrite behavior inconsistently) because required user 
fields are omitted. Build the payload from the current user (using the new 
helper) and include `password` in the same request body. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Users list "Reset password" action returns backend error.
   - ❌ Admins cannot reset passwords via Users List UI.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start Superset with this PR code and log in as an admin user, then 
navigate to the
   Users list page implemented in 
`superset-frontend/src/pages/UsersList/index.tsx:20-37`,
   where `useListViewResource('security/users', ...)` powers the listing.
   
   2. In the Users list actions column
   (`superset-frontend/src/pages/UsersList/index.tsx:5-31` in the 332–391 
block), click the
   "Reset password" action (`label: 'user-list-reset-password-action'`), which 
runs
   `handleResetPassword` that sets `currentUser` and calls
   `openModal(ModalType.RESET_PASSWORD)`, causing `UserListResetPasswordModal` 
to render
   (`index.tsx:568-580`).
   
   3. In `UserListResetPasswordModal`
   
(`superset-frontend/src/features/users/UserListResetPasswordModal.tsx:80-107`), 
enter a
   new password and confirmation and submit; the modal's `handleFormSubmit` 
calls
   `resetUserPassword(user.id, rest.password)` at line 90, passing only the 
user id and the
   new password to the utility.
   
   4. The `resetUserPassword` implementation in
   `superset-frontend/src/features/users/utils.ts:38-47` performs 
`SupersetClient.put` to
   `/api/v1/security/users/${userId}` with `jsonPayload: { password }` only, 
but the OpenAPI
   spec for `PUT /api/v1/security/users/{pk}`
   (`docs/static/resources/openapi.json:35582-159`) documents a 
`SupersetUserApi.put` schema
   expecting a full user update payload (e.g., `active`, `email`, `first_name`, 
`last_name`,
   `roles`, `groups`, `username`, plus `password`), and the same endpoint is 
used for normal
   edits via `updateUser(user.id, values)` with full form values in 
`UserListModal`
   (`superset-frontend/src/features/users/UserListModal.tsx:45-51`). As a 
result, sending
   only `{ password }` can trigger backend validation errors or unintended 
overwrites of
   other fields, causing the admin password reset API call to fail and the UI 
to show an
   error toast instead of successfully updating the password.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2ff77683ea164e3bb74caecd819f3ed2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2ff77683ea164e3bb74caecd819f3ed2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/features/users/utils.ts
   **Line:** 38:48
   **Comment:**
        *Api Mismatch: The admin reset-password request sends only `password` 
to `PUT /api/v1/security/users/:id`, but this endpoint expects the full user 
update payload in this codebase flow. As written, password resets can fail with 
validation errors (or overwrite behavior inconsistently) because required user 
fields are omitted. Build the payload from the current user (using the new 
helper) and include `password` in the same request body.
   
   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%2F39469&comment_hash=9a2e7e3861bae56abadf1214c58219c92051ffcc46eaa1ee32803a58ecf3e5ed&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39469&comment_hash=9a2e7e3861bae56abadf1214c58219c92051ffcc46eaa1ee32803a58ecf3e5ed&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]

Reply via email to