dify/api/schedule
GareArc 8a62c1d915
chore(api): pyright + ruff cleanup for openapi/cli surface
Type and lint pass over the openapi controllers, auth pipeline, and
oauth bearer/device-flow plumbing. Down from 36 pyright errors and 16
ruff errors to 0/0; 93 openapi unit tests pass.

Logic fixes:
- libs/oauth_bearer.py: drop private-naming on the friend-API methods
  consumed by _VariantResolver (cache_get / cache_set_positive /
  cache_set_negative / hard_expire / session_factory). They were always
  cross-class accessors — leading underscore was misleading. Add public
  registry property on BearerAuthenticator. _hard_expire row_id widened
  to UUID | str (matches the StringUUID column type).
- libs/oauth_bearer.py: type validate_bearer / bearer_feature_required
  with ParamSpec / PEP-695 so wrapped routes preserve their signature.
- libs/rate_limit.py: same — typed rate_limit decorator.
- services/oauth_device_flow.py: mint_oauth_token / _upsert accept
  Session | scoped_session (Flask-SQLAlchemy proxy). Guard row-is-None
  after upsert.
- controllers/openapi/{chat,completion,workflow}_messages.py: tuple-vs-
  Mapping shape narrowing on AppGenerateService.generate return —
  production returns Mapping, tests mock as (body, status). Validate
  through Pydantic Response model in both shapes.
- controllers/openapi/oauth_device.py: replace flask_restx.reqparse (banned)
  with Pydantic Request/Query models — DeviceCodeRequest, DevicePollRequest,
  DeviceLookupQuery, DeviceMutateRequest. Two PEP-695 generic helpers
  (_validate_json / _validate_query) translate ValidationError to BadRequest.
- controllers/openapi/auth/strategies.py: Protocol param-name match
  (subject_type), Optional narrowing on app/tenant/account_id/subject_email.
- controllers/openapi/auth/steps.py: subject_type-is-None guard before
  mounter dispatch.
- core/app/apps/workflow/generate_task_pipeline.py + models/workflow.py:
  add WorkflowAppLogCreatedFrom.OPENAPI + matching match-case branch.
  Fixes match-exhaustiveness and possibly-unbound created_from.
- libs/device_flow_security.py: pyright ignore on flask after_request
  hook (registered by the framework, pyright sees as unused).
- services/oauth_device_flow.py: rename Exceptions to *Error suffix
  (StateNotFoundError / InvalidTransitionError / UserCodeExhaustedError);
  same for libs/oauth_bearer.py (InvalidBearerError / TokenExpiredError).
  Update all callers across openapi controllers.
- controllers/openapi/{oauth_device,oauth_device_sso}.py +
  services/oauth_device_flow.py: switch logger.error in except blocks
  to logger.exception (TRY400) — keeps the traceback for ops.
- configs/feature/__init__.py: OPENAPI_KNOWN_CLIENT_IDS computed_field
  needs an @property alongside for pyright to see it as a value, not a
  method. Matches the existing line-451 pattern.

Plus ruff format + import-sort across the openapi tree (pure formatting).
2026-04-28 21:44:54 -07:00
..
check_upgradable_plugin_task.py refactor: migrate db.session.query to select in infra layer (#33694) 2026-03-19 15:48:29 +09:00
clean_embedding_cache_task.py refactor: migrate db.session.query to select in infra layer (#33694) 2026-03-19 15:48:29 +09:00
clean_messages.py feat: add lock for retention jobs (#31320) 2026-01-21 14:06:35 +08:00
clean_oauth_access_tokens_task.py chore(api): pyright + ruff cleanup for openapi/cli surface 2026-04-28 21:44:54 -07:00
clean_unused_datasets_task.py refactor: migrate db.session.query to select in infra layer (#33694) 2026-03-19 15:48:29 +09:00
clean_workflow_runlogs_precise.py refactor: migrate session.query to select API in schedule cleanup task (#34775) 2026-04-08 23:12:57 +00:00
clean_workflow_runs_task.py feat: add lock for retention jobs (#31320) 2026-01-21 14:06:35 +08:00
create_tidb_serverless_task.py feat: tidb endpoint (#35158) 2026-04-15 08:46:25 +00:00
mail_clean_document_notify_task.py chore(api): migrate mail task and OAuth data source to use Session(db… (#35235) 2026-04-17 08:52:27 +00:00
queue_monitor_task.py refactor: reuse redis connection instead of create new one (#32678) 2026-03-09 15:53:21 +08:00
trigger_provider_refresh_task.py refactor: reuse redis connection instead of create new one (#32678) 2026-03-09 15:53:21 +08:00
update_api_token_last_used_task.py fix: redis for api token (#31861) 2026-02-06 16:25:27 +08:00
update_tidb_serverless_status_task.py refactor: move vdb implementations to workspaces (#34900) 2026-04-13 08:56:43 +00:00
workflow_schedule_task.py refactor: reuse redis connection instead of create new one (#32678) 2026-03-09 15:53:21 +08:00