Skip to content

refactor(api): type _sign_query return with SignedQueryDict TypedDict#34981

Open
aviu16 wants to merge 1 commit intolanggenius:mainfrom
aviu16:refactor/type-sign-query
Open

refactor(api): type _sign_query return with SignedQueryDict TypedDict#34981
aviu16 wants to merge 1 commit intolanggenius:mainfrom
aviu16:refactor/type-sign-query

Conversation

@aviu16
Copy link
Copy Markdown
Contributor

@aviu16 aviu16 commented Apr 12, 2026

Part of #32863 (api/core/app/workflow/file_runtime.py)

Summary

  • Define SignedQueryDict TypedDict for the _sign_query return type
  • Replace dict[str, str] return annotation with the new TypedDict

Why this change

_sign_query returns a fixed 3-key dict (timestamp, nonce, sign) used as URL query params for signed file access. The bare dict[str, str] hides this structure from callers and downstream urllib.parse.urlencode usage.

Changes

  • api/core/app/workflow/file_runtime.py: Define SignedQueryDict, annotate _sign_query return type

@aviu16 aviu16 requested a review from QuantumGhost as a code owner April 12, 2026 03:14
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Apr 12, 2026
@asukaminato0721 asukaminato0721 requested a review from Copilot April 12, 2026 03:35
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-12 03:36:44.561506228 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-12 03:36:36.871330018 +0000
@@ -20,6 +20,8 @@
    --> core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py:321:29
 ERROR Argument `list[Unknown]` is not assignable to parameter `value` with type `SQLCoreOperations[dict[str, Any]] | dict[str, Any]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
    --> core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py:388:27
+ERROR TypedDict `SignedQueryDict` does not have key `as_attachment` [bad-typed-dict-key]
+   --> core/app/workflow/file_runtime.py:107:19
 ERROR No matching overload found for function `core.model_manager.ModelInstance.invoke_llm` called with arguments: (prompt_messages=list[UserPromptMessage], model_parameters=dict[str, int], stream=Literal[False]) [no-matching-overload]
   --> core/llm_generator/llm_generator.py:85:60
 ERROR No matching overload found for function `core.model_manager.ModelInstance.invoke_llm` called with arguments: (prompt_messages=list[UserPromptMessage], model_parameters=dict[str, float | int], stream=Literal[False]) [no-matching-overload]

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Introduces a SignedQueryDict TypedDict to make _sign_query’s fixed query-parameter shape explicit and updates _sign_query’s return annotation accordingly.

Changes:

  • Add SignedQueryDict TypedDict (timestamp, nonce, sign)
  • Update _sign_query return type from dict[str, str] to SignedQueryDict
Comments suppressed due to low confidence (1)

api/core/app/workflow/file_runtime.py:143

  • Changing _sign_query to return a total SignedQueryDict makes resolve_upload_file_url()'s query["as_attachment"] = "true" assignment a type error because as_attachment is not a declared key on the TypedDict. Either (a) include as_attachment: NotRequired[str] on the query TypedDict used by resolve_upload_file_url, or (b) keep _sign_query returning SignedQueryDict but copy/widen before mutation (e.g., cast/dict()/{**...} to dict[str, str]) so adding extra query params is type-safe.
    def _sign_query(self, *, payload: str) -> SignedQueryDict:
        timestamp = str(int(time.time()))
        nonce = os.urandom(16).hex()
        sign = hmac.new(self._secret_key(), f"{payload}|{timestamp}|{nonce}".encode(), hashlib.sha256).digest()
        return {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants