Skip to content

Bump flask-admin to 2.1.0 (replaces dependabot #662)#665

Merged
neoneye merged 1 commit intomainfrom
fix/flask-admin-2.1.0-typecheck
May 3, 2026
Merged

Bump flask-admin to 2.1.0 (replaces dependabot #662)#665
neoneye merged 1 commit intomainfrom
fix/flask-admin-2.1.0-typecheck

Conversation

@neoneye
Copy link
Copy Markdown
Member

@neoneye neoneye commented May 3, 2026

Summary

Replaces dependabot PR #662, which failed CI typecheck with 10 errors in frontend_multi_user/src/planexe_modelviews.py. This branch bumps the dep AND fixes the typecheck breakage.

Root cause

flask-admin 2.1.0 retyped ModelView attributes:

  • session is now assigned via _warn_session_deprecation(...), whose overload pair pyright resolves to None. So every self.session.query/.add/.commit/.get access fails type-checking.
  • model is now typed type[T_SQLALCHEMY_MODEL], which pyright resolves to type[Any] | type[DeclarativeBase]. DeclarativeBase has no project-specific columns, so self.model.id / .generated_report_html etc fail.

Fix

Static-analysis-only — runtime behaviour is unchanged. Add TYPE_CHECKING-guarded imports of sqlalchemy.orm.Session and PlanItem, then narrow the inherited attribute annotations:

class AdminOnlyModelView(ModelView):
    if typing.TYPE_CHECKING:
        session: Session  # narrow inherited attr for static analysis

class PlanItemView(AdminOnlyModelView):
    if typing.TYPE_CHECKING:
        model: type[PlanItem]  # narrow inherited attr for static analysis

Session narrowing propagates to all AdminOnlyModelView subclasses. Model narrowing only applies where project-specific columns are accessed.

Test plan

  • Local pyright: 0 errors on src/planexe_modelviews.py (was 10)
  • CI green
  • User-tested in admin panel (if needed)

Closes

🤖 Generated with Claude Code

Dependabot PR #662 (flask-admin 2.0.2 → 2.1.0) failed
typecheck with 10 errors in src/planexe_modelviews.py:

- 6× "Cannot access attribute X for class None" on self.session
  (e.g. `self.session.query(...)`, `.commit()`, `.add()`,
  `.get()`).
- 4× "Cannot access attribute X for class type[DeclarativeBase]"
  on self.model column attributes (PlanItem.generated_report_html,
  .run_zip_snapshot, .run_track_activity_jsonl, .id).

Root cause: flask-admin 2.1.0 retyped ModelView's attributes.
`session` is now stored via `_warn_session_deprecation(...)`
whose overload pair pyright resolves to `None`. `model` is now
typed as `type[T_SQLALCHEMY_MODEL]`, which pyright resolves to
`type[Any] | type[DeclarativeBase]` — DeclarativeBase has no
project-specific columns.

Fix is static-analysis-only — runtime behaviour unchanged. Add
TYPE_CHECKING-guarded imports of sqlalchemy.orm.Session and
PlanItem, then narrow the inherited attribute annotations on
the relevant subclasses:

  class AdminOnlyModelView(ModelView):
      if typing.TYPE_CHECKING:
          session: Session
      ...

  class PlanItemView(AdminOnlyModelView):
      if typing.TYPE_CHECKING:
          model: type[PlanItem]
      ...

The session narrowing on the base class propagates to all
subclasses (UserAccountView, etc.). The model narrowing only
applies where project-specific columns are accessed.

Local verification: pyright reports 0 errors on
src/planexe_modelviews.py (was 10). The remaining 2
project-wide pyright errors (authlib, stripe import-
resolution) are pre-existing and unrelated to this change.
@neoneye neoneye merged commit f9b8030 into main May 3, 2026
3 checks passed
@neoneye neoneye deleted the fix/flask-admin-2.1.0-typecheck branch May 3, 2026 12:56
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.

1 participant