dify/api/extensions
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
..
logstore chore: reorg imports (#35308) 2026-04-16 08:50:02 +00:00
otel chore: reorg imports (#35308) 2026-04-16 08:50:02 +00:00
storage refactor: replace bare dict with dict[str, Any] in models, providers, extensions, libs, and test utilities (#35186) 2026-04-14 17:51:25 +00:00
__init__.py feat: mypy for all type check (#10921) 2024-12-24 18:38:51 +08:00
ext_app_metrics.py Removes the 'extensions' directory from pyrightconfig.json and fixes … (#26512) 2025-10-05 15:57:42 +09:00
ext_blueprints.py feat(api): retire legacy /v1/* and /console/api device-flow mounts (Phase F) 2026-04-27 00:45:10 -07:00
ext_celery.py feat(api,web): OAuth 2.0 device flow + bearer auth (RFC 8628) 2026-04-26 20:06:43 -07:00
ext_code_based_extension.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
ext_commands.py feat: add export app messages (#32990) 2026-03-07 11:27:15 +08:00
ext_compress.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
ext_database.py fix: fix db env not work (#30541) 2026-01-05 11:10:45 +08:00
ext_enterprise_telemetry.py feat: enterprise otel exporter (#33138) 2026-03-27 07:56:31 +00:00
ext_fastopenapi.py refactor(api): tighten phase 1 shared type contracts (#33453) 2026-03-17 17:50:51 +08:00
ext_forward_refs.py feat(api): automatically NODE_TYPE_CLASSES_MAPPING generation from node class definitions (#28525) 2025-12-01 14:14:19 +08:00
ext_hosting_provider.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
ext_import_modules.py Removes the 'extensions' directory from pyrightconfig.json and fixes … (#26512) 2025-10-05 15:57:42 +09:00
ext_logging.py feat(refactoring): Support Structured Logging (JSON) (#30170) 2026-01-04 11:46:46 +08:00
ext_login.py feat(openapi): cookie auth for device-flow approval routes 2026-04-28 20:41:38 -07:00
ext_logstore.py fix(logstore): prevent SQL injection, fix serialization issues, and optimize initialization (#30697) 2026-01-14 10:21:26 +08:00
ext_mail.py chore: add ast-grep rule to convert Optional[T] to T | None (#25560) 2025-09-15 13:06:33 +08:00
ext_migrate.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
ext_oauth_bearer.py chore(api): pyright + ruff cleanup for openapi/cli surface 2026-04-28 21:44:54 -07:00
ext_orjson.py remove bare list, dict, Sequence, None, Any (#25058) 2025-09-06 03:32:23 +08:00
ext_otel.py feat: enterprise otel exporter (#33138) 2026-03-27 07:56:31 +00:00
ext_proxy_fix.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
ext_redis.py feat: support configurable redis key prefix (#35139) 2026-04-14 09:31:41 +00:00
ext_request_logging.py feat: add x-trace-id to http responses and logs (#29015) 2025-12-02 17:22:34 +08:00
ext_sentry.py chore: reorg imports (#35308) 2026-04-16 08:50:02 +00:00
ext_session_factory.py refactor: admin api using session factory (#29628) 2025-12-15 12:01:41 +08:00
ext_set_secretkey.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
ext_socketio.py feat: collaboration (#30781) 2026-04-16 02:21:04 +00:00
ext_storage.py refactor(workflow-file): move core.file to core.workflow.file (#32252) 2026-02-16 22:38:19 +08:00
ext_timezone.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
ext_warnings.py refactor: assembling the app features in modular way (#9129) 2024-11-30 23:05:22 +08:00
redis_names.py feat: support configurable redis key prefix (#35139) 2026-04-14 09:31:41 +00:00