-
Notifications
You must be signed in to change notification settings - Fork 16.3k
fix(marshmallow): add compatibility layer for Flask-AppBuilder with marshmallow 4.x #35920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Based on your review schedule, I'll hold off on reviewing this PR until it's marked as ready for review. If you'd like me to take a look now, comment
|
|
/korbit-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Redundant JSON serialization without caching ▹ view | ||
| Sanitized data stored but not consumed ▹ view | ||
| Missing import for Length validator ▹ view | ||
| Module-level patch execution adds import overhead ▹ view | ||
| Marshmallow patch applied at module level ▹ view | ||
| Inefficient retry loop with redundant field processing ▹ view | ||
| Unmanaged Monkey-Patching of External Library ▹ view | ||
| Improper Logging Mechanism ▹ view | ||
| Unreliable KeyError message parsing ▹ view | ||
| Unsafe declared_fields modification ▹ view |
Files scanned
| File Path | Reviewed |
|---|---|
| superset/advanced_data_type/schemas.py | ✅ |
| superset/marshmallow_compatibility.py | ✅ |
| superset/themes/schemas.py | ✅ |
| superset/app.py | ✅ |
| superset/db_engine_specs/databend.py | ✅ |
| superset/reports/schemas.py | ✅ |
| superset/charts/schemas.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
|
@mistercrunch Hi, could you re-run workflows on this PR? Also lmk if you have any concerns/suggestions about the compatibility changes here. Much appreciated 🙏 |
|
re-running workflows 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR upgrades marshmallow from version 3.x to 4.x to resolve compatibility issues with Flask-AppBuilder 5.0.0. The upgrade addresses a critical initialization error where Flask-AppBuilder auto-generates schema fields for SQLAlchemy relationships that don't pass marshmallow 4.x's stricter field validation.
Key Changes:
- Introduces a compatibility layer that patches marshmallow's
Schema._init_fieldsto dynamically add missing auto-generated fields as Raw fields - Updates all marshmallow schemas to follow 4.x conventions (validator signatures, field parameters, metadata usage)
- Upgrades marshmallow to >=4.0.0 and marshmallow-sqlalchemy to 1.4.2
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| superset/marshmallow_compatibility.py | New module that patches marshmallow to handle Flask-AppBuilder compatibility by dynamically adding missing fields |
| superset/app.py | Applies the marshmallow compatibility patch during application initialization |
| tests/unit_tests/test_marshmallow_compatibility.py | Comprehensive unit tests for the compatibility module |
| superset/themes/schemas.py | Migrates validators to accept **kwargs parameter and replaces self.context with ContextVar |
| superset/reports/schemas.py | Updates validator signatures and replaces default with load_default |
| superset/models/helpers.py | Updates validator signature to include **kwargs |
| superset/databases/schemas.py | Updates validator signature to include **kwargs |
| superset/charts/schemas.py | Migrates field parameters: description to metadata, minLength to validate=Length(), min to validate=Range() |
| superset/db_engine_specs/databend.py | Migrates description to metadata and default to dump_default |
| superset/advanced_data_type/schemas.py | Updates JSON schema with dump_default (needs correction) |
| pyproject.toml | Updates marshmallow dependency from >=3.0, <4 to >=4 |
| requirements/base.in | Updates marshmallow-sqlalchemy from <1.4.1 to >=1.4.2 |
| requirements/base.txt | Locks marshmallow at 4.0.0 and marshmallow-sqlalchemy at 1.4.2 |
| requirements/development.txt | Locks marshmallow at 4.0.0 and marshmallow-sqlalchemy at 1.4.2 |
…anup Feature/marshmallow upgrade cleanup
|
@rusackas The tests/checks should be all fixed now (hopefully). Could you rerun once again? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #35920 +/- ##
===========================================
+ Coverage 0 67.55% +67.55%
===========================================
Files 0 637 +637
Lines 0 46847 +46847
Branches 0 5084 +5084
===========================================
+ Hits 0 31646 +31646
- Misses 0 13912 +13912
- Partials 0 1289 +1289
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…anup Fix ruff and mympy checks
|
The above commit should fix the remaining checks 33c0814
|

SUMMARY
Upgrades marshmallow version to >= 4.0
KeyErrorduring schema initialization.Schema._init_fieldsmethod to detect missing fields that Flask-AppBuilder 5.0.0 auto-generates, and then adds these missing fields dynamically as raw fields with appropriate flags & retry initialization until all missing fields are resolved.marshmallow_fix.pymodule, whose job is to specifically address the Flask-AppBuilder 5.0.0 incompatibility with marshmallow 4.x, and thenapp.pyapplies the patch by importing it frommarshmallow_fix.py.app.pyandmarshmallow_fix.pyare minor convention/syntax changes that are required for the Marshmallow upgrade to >= 4.0.0 (See https://marshmallow.readthedocs.io/en/stable/upgrading.html for more info)BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
BEFORE: Upon pinning

marshmallow>=4inpyproject.tomland initializing the superset app, an initialization error occurs.AFTER: App runs without error

TESTING INSTRUCTIONS
Start superset application, see that no marshmallow related errors show up.
Run tests with
docker compose run --rm superset python -m pytest tests/unit_tests/test_marshmallow_compatibility.py -vUnit tests created:
ADDITIONAL INFORMATION
marshmallow>=4.0.0#33162Credit to
@Austin-X @Eyang0612 @PDOracle @MasahisaSekita