Skip to content

Conversation

@yangcao77
Copy link
Contributor

@yangcao77 yangcao77 commented Sep 9, 2025

Description

This PR is to fix the issue introduced by 86bf3fa#diff-161203a480e136c4249f169f65c47e15a5092b6623a1193fa5bbca78ee811d4f

the auth now unpack to 4 args. but the above commit missed the updated in conversations endpoint.
and thus, will see the following error when use no-op auth method:

  File "/Users/stephanie/Documents/RHDH/lightspeed-stack/src/authorization/middleware.py", line 118, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stephanie/Documents/RHDH/lightspeed-stack/src/app/endpoints/conversations.py", line 252, in get_conversation_endpoint_handler
    user_id, _, _ = auth
    ^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 3)

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #
  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

verified the conversations endpoint now works

Screenshot 2025-09-09 at 1 23 27 PM Screenshot 2025-09-09 at 1 24 11 PM

Summary by CodeRabbit

  • Refactor
    • Internal authentication handling for conversation endpoints adjusted to a different auth value structure; no changes to request/response behavior, authorization checks, or error handling.
    • No public API changes; existing clients continue to work without modification.
  • Tests
    • Unit tests updated to reflect the new auth value structure (no user-facing impact).

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 9, 2025

Walkthrough

Changed how endpoint handlers extract the authenticated user id: handlers now index auth[0] instead of unpacking a 3-tuple. Tests updated to provide a 4-tuple MOCK_AUTH. No endpoint signatures, control flow, or error handling were modified.

Changes

Cohort / File(s) Summary
Endpoint auth extraction update
src/app/endpoints/conversations.py
Replaced tuple unpacking in get_conversations_list_endpoint_handler, get_conversation_endpoint_handler, and delete_conversation_endpoint_handler to derive user_id via auth[0] instead of (user_id, _, _). No other logic changes.
Test auth fixture update
tests/unit/app/endpoints/test_conversations.py
Updated MOCK_AUTH from a 3-tuple to a 4-tuple (added False before the token) so tests match the new auth shape used by endpoints.

Sequence Diagram(s)

(No sequence diagram provided — changes are limited to how auth is read internally and do not alter control flow or interactions.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • maorfr
  • tisnik

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title “fix conversations endpoint error” is a concise, single-sentence summary that accurately highlights the primary change of this pull request, which is correcting the unpacking error in the conversations endpoint introduced by the prior commit.
Description Check ✅ Passed The pull request description clearly details the issue, root cause, specific error trace, and the resolution steps, including references to the related commit and verification screenshots, making it directly relevant to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Poem

I nibble tuples, one by one,
Pluck the id, the rest weigh none.
Endpoints hum and tests agree,
Little paws fix consistency.
Carrots crunch — CI's green for me. 🥕

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/app/endpoints/conversations.py (2)

374-375: Inconsistent tuple shape handling; unify with the same fix.

This still assumes a 3-tuple. Use the same approach to work with both shapes.

-    user_id, _, _ = auth
+    user_id = auth[0]

156-160: Align auth tuple unpack to returned 4-tuple
In src/app/endpoints/conversations.py around line 374, change

user_id, _, _ = auth

to

user_id, _, _, _ = auth

so it matches the 4-value shape used elsewhere (e.g. streaming_query). Then update any mocks or test doubles still returning a 3-tuple to include the new field.

🧹 Nitpick comments (1)
src/app/endpoints/conversations.py (1)

156-160: Optional: centralize user_id extraction to a helper for consistency.

Avoid repeating auth-shape assumptions by adding a small helper (e.g., extract_user_id(auth) -> str) and call it in all handlers.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ba31bd and 8a370ba.

📒 Files selected for processing (1)
  • src/app/endpoints/conversations.py (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Unit tests
src/app/endpoints/conversations.py

[error] 252-252: ValueError: not enough values to unpack (expected 4, got 3) while unpacking 'auth' in get_conversation_endpoint_handler (src/app/endpoints/conversations.py:252). Command: uv run pytest tests/unit --cov=src --cov=runner --cov-report term-missing

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests

Signed-off-by: Stephanie <[email protected]>
Signed-off-by: Stephanie <[email protected]>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a370ba and 6f8a959.

📒 Files selected for processing (2)
  • src/app/endpoints/conversations.py (3 hunks)
  • tests/unit/app/endpoints/test_conversations.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/endpoints/conversations.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests
🔇 Additional comments (1)
tests/unit/app/endpoints/test_conversations.py (1)

24-24: LGTM: tests now match 4-tuple auth shape

Updating MOCK_AUTH to a 4-tuple aligns tests with the middleware change and prevents the previous unpacking error.

from tests.unit.utils.auth_helpers import mock_authorization_resolvers

MOCK_AUTH = ("mock_user_id", "mock_username", "mock_token")
MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Make auth shape explicit to avoid positional brittleness

Consider a NamedTuple to document fields and reduce future breakage if order changes.

+from typing import NamedTuple
+
+class MockAuth(NamedTuple):
+    user_id: str
+    username: str
+    is_admin: bool
+    token: str
+
-MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
+MOCK_AUTH = MockAuth("mock_user_id", "mock_username", False, "mock_token")

Run to spot any lingering tuple-unpacking of auth or assumptions about a 3-tuple:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Potential outdated 3-item destructuring of auth:"
rg -nP --type=py -C2 '\b(?:\w+|_)\s*,\s*(?:\w+|_)\s*,\s*(?:\w+|_)\s*=\s*auth\b'

echo
echo "Any tuple destructuring of auth (manual review recommended):"
rg -nP --type=py -C1 '\(\s*[^()]+\s*(?:,\s*[^()]+){2,}\s*\)\s*=\s*auth\b'

echo
echo "Common legacy pattern (user_id, _, _ = auth):"
rg -nP --type=py -C2 '\buser_id\s*,\s*_\s*,\s*_\s*=\s*auth\b'

echo
echo "Callers using 4th element (index 3) of auth:"
rg -nP --type=py -C2 'auth\[\s*3\s*\]'

echo
echo "All MOCK_AUTH definitions:"
rg -n --type=py 'MOCK_AUTH\s*='

Length of output: 2361


Define MockAuth NamedTuple and replace positional auth unpacking with attribute access

+from typing import NamedTuple
+
+class MockAuth(NamedTuple):
+    user_id: str
+    username: str
+    is_admin: bool
+    token: str
+
-MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
+MOCK_AUTH = MockAuth("mock_user_id", "mock_username", False, "mock_token")

Detected residual positional destructuring in:

  • src/authorization/resolvers.py:84 (_, _, _, token = auth)
  • src/app/endpoints/authorized.py:53 (user_id, user_name, skip_userid_check, _ = auth)
  • src/app/endpoints/feedback.py:113 & 198 (user_id, _, _, _ = auth)
  • src/app/endpoints/query.py:183 (user_id, _, _, token = auth)
  • src/app/endpoints/streaming_query.py:559 (user_id, _user_name, _skip_userid_check, token = auth)

Update each to use auth.user_id, auth.username, auth.is_admin, and auth.token instead of tuple unpacking.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
from typing import NamedTuple
class MockAuth(NamedTuple):
user_id: str
username: str
is_admin: bool
token: str
MOCK_AUTH = MockAuth("mock_user_id", "mock_username", False, "mock_token")
🤖 Prompt for AI Agents
In tests/unit/app/endpoints/test_conversations.py around line 24 and in the
listed resolver/endpoints (src/authorization/resolvers.py around line 84,
src/app/endpoints/authorized.py around line 53, src/app/endpoints/feedback.py
around lines 113 and 198, src/app/endpoints/query.py around line 183, and
src/app/endpoints/streaming_query.py around line 559) the code still unpacks a
positional auth tuple; define a NamedTuple (e.g., MockAuth with fields user_id,
username, is_admin, token) and replace all positional destructuring with
attribute access (auth.user_id, auth.username, auth.is_admin, auth.token) and
update tests to use MockAuth(...) instead of a plain tuple to keep usage clear
and type-safe.

Copy link
Contributor

@tisnik tisnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you

@tisnik tisnik merged commit e4c7aa1 into lightspeed-core:main Sep 10, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants