Repository navigation
Conversation
Annotate the free plan tenant cleanup test so it passes the strict pyrefly project check, then drop its entry from project-excludes. Twelve diagnostics are cleared. The frozen clock subclass now returns an instance of itself, matching what `datetime.now` declares, and marks the override; the value it returns is still the pinned instant. The conversation status uses the real enum instead of the literal string, three expiring batches use `list[object]()` so the element type is known, and ruff reports no import drift. No ignores, no casts, no typing.Any.
Pyrefly Diffbase → PR |
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… sweep pyrefly could not see `.kw` or `.id` on the `object`-typed placeholders. Declare the collected session makers as `sessionmaker[Session]` and read each record id through an explicit local before asserting it is present.
Naming `record.id` fails the strict check because the shared declarative base declares no such attribute, and `getattr` is blocked by the new-getattr guard. The identity SQLAlchemy already tracks is the same value the `Session.get` lookups below use.
The cleanup service widened its rows to 'object' because the cleaned models share an 'id' primary key without a common declarative base, so callers had to work around the missing attribute. Publish the shared row type from the origin code and type the service against it.
The two batch loop tests simulated the repository boundary with MagicMock, so they asserted call counts on a stand-in instead of proving that the production repositories really remove the rows they hand back. Both tests now write expired rows to the SQLite database and call the real factory, then verify from a fresh session that the rows are gone. Because a broken delete would otherwise make the loop spin forever, the repositories are wrapped in a forwarding bound that raises after the second batch, so a regression fails in seconds with a clear message. Verified by mutating each delete call to return 0: both mutations fail the suite in ~10s, and the unmodified tree passes 13 tests.
There was a problem hiding this comment.
3 inline suggestions at b6ab64e3e5, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
|
Replaced both repository stand-ins with the real repositories.
One thing worth flagging: a broken delete previously made the cleanup loop spin forever, so a regression would hang the suite instead of failing it. Both tests now wrap the real repositories in a forwarding bound that raises after the second batch, which keeps the production path intact while making the failure immediate. I confirmed this by mutating each delete call to return 0: both mutations fail the suite in about ten seconds, and the unmodified tree reports 13 passed. |
The bounded wrappers used __getattr__ to delegate everything else, which the no-new-getattr guard rejects. The wrappers only need the two repository calls the tests exercise, so both are forwarded explicitly instead.
There was a problem hiding this comment.
1 inline suggestion at 8206b933ea, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.
dify-codereview
| class ClearFreePlanTenantExpiredLogs: | ||
| @staticmethod | ||
| def _serialize_record(record: object) -> dict[str, object]: | ||
| def _serialize_record(record: MessageRelatedRecord | WorkflowNodeExecutionModel) -> dict[str, object]: |
There was a problem hiding this comment.
Parse, don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/): model this data once at the boundary as a pydantic model / dataclass / TypedDict (Model.model_validate(raw)), and pass the typed value on, instead of passing dicts around and re-checking keys and types where they are used. In a test, don't build this as an ad hoc dict[str, object]: define the shape (TypedDict / model) in the production code and import it here.
dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.
The two factory helpers that build the bounded wrappers still declared an `object` return type, so the type checker could not see that the tests hand the real repository calls through typed wrappers.
…-app-generator Resolve import-block conflicts by keeping both sides' imports and letting ruff isort re-sort them; no behavioural change.
Why
api/tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.pyis still listed inproject-excludes, so it is never checked under strict pyrefly.Summary
Brings the module under strict checking and removes its entry from
project-excludes(208 → 207 entries).Twelve diagnostics are cleared:
bad-override+ 2 ×missing-override-decoratoron the frozen-clock subclass.datetime.nowis declared to return the subclass itself, so the helper now returnscls.fromtimestamp(...)of the pinned instant and marks the override. Microseconds and tzinfo survive the round trip, so the value the test freezes is still the same instant.bad-argument-type→ the conversation status usesConversationStatus.NORMALinstead of the literal"normal". It is aStrEnumwhose value is that string, so the persisted value is unchanged.implicit-any-empty-container→ the "no more rows" entries in the batchside_effectlists uselist[object]()so their element type is known.No
# pyrefly: ignore, no# type: ignore, notyping.cast, notyping.Any.Verification
api/tests/unit_tests, pyrefly 1.5.0-dev.1 with the repo venv interpreter):ERROR29 with all 29 being the pre-existingmissing-importnoise.WARN0. Target file residual 0.pyteston the file → 13 passed.ruff checkandruff format --checkclean.