Skip to content

fix: lazy-load auth deps in web/Pyodide startup and add regression tests#6280

Merged
FeodorFitsner merged 9 commits intomainfrom
fix-web-build
Mar 9, 2026
Merged

fix: lazy-load auth deps in web/Pyodide startup and add regression tests#6280
FeodorFitsner merged 9 commits intomainfrom
fix-web-build

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Mar 8, 2026

Fix #6258

Summary by Sourcery

Lazy-load optional authentication dependencies to avoid import-time failures when auth is unused and add regression tests to validate this behavior.

New Features:

  • Introduce lazy attribute resolution in the flet.auth package so auth service and provider classes are loaded on first access rather than at module import time.

Bug Fixes:

  • Prevent failures when importing flet or flet.auth in environments where optional auth dependencies (httpx, oauthlib) are not installed by deferring their imports until actually needed.

Enhancements:

  • Adjust authorization service internals to work with lazily imported dependencies while keeping the public API unchanged.

Tests:

  • Add regression tests ensuring flet imports successfully without optional auth dependencies, auth exports remain accessible, and oauthlib is only required when authorization logic is invoked.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine

Copy link
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

Fixes a Pyodide/web startup crash caused by eager imports of optional auth dependencies (httpx, oauthlib) by deferring those imports until the relevant auth code paths are actually used.

Changes:

  • Made httpx imports lazy in GitHubOAuthProvider user/group fetching.
  • Made httpx/oauthlib imports lazy in AuthorizationService (and adjusted typing to avoid oauthlib types at import-time).
  • Added regression tests ensuring import flet / import flet.auth succeed when httpx and oauthlib are unavailable.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
sdk/python/packages/flet/tests/test_auth_lazy_imports.py Adds regression tests that simulate missing optional auth deps and validate lazy-import behavior.
sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py Moves httpx import into the async fetch methods to avoid import-time dependency.
sdk/python/packages/flet/src/flet/auth/authorization_service.py Defers httpx/oauthlib imports to call sites and removes oauthlib type imports from module import-time.
sdk/python/packages/flet/src/flet/auth/init.py Lazily exposes auth exports via module __getattr__ to avoid eager importing of auth implementation/provider modules.

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

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 8, 2026

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: da92691
Status: ✅  Deploy successful!
Preview URL: https://f84dedff.flet-docs.pages.dev
Branch Preview URL: https://fix-web-build.flet-docs.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 8, 2026

Deploying flet-examples with  Cloudflare Pages  Cloudflare Pages

Latest commit: da92691
Status: ✅  Deploy successful!
Preview URL: https://019fcd4e.flet-examples.pages.dev
Branch Preview URL: https://fix-web-build.flet-examples.pages.dev

View logs

ndonkoHenri and others added 4 commits March 9, 2026 05:14
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Import pytest and add pytestmark = pytest.mark.skip(reason="Temporarily disabled") in sdk/python/packages/flet/tests/test_object_diff_memory_churn.py to temporarily disable the memory churn test.
@FeodorFitsner FeodorFitsner merged commit 133f1bc into main Mar 9, 2026
54 checks passed
@FeodorFitsner FeodorFitsner deleted the fix-web-build branch March 9, 2026 16:34
@FeodorFitsner FeodorFitsner added this to the 0.82.1 milestone Mar 9, 2026
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.

bug: Flet app built with flet build web crashes after failing to find httpx and oauthlib packages

3 participants