Fix FAB session cookie TypeError with Werkzeug 3.0+#67141
Conversation
Switch _LazySafeSerializer from msgspec.msgpack (returns bytes) to msgspec.json (returns str) so that Werkzeug 3.0+ dump_cookie() works correctly. The loads() method tries JSON first and falls back to msgpack for backward compatibility with sessions written before this change. closes: apache#64921
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
|
@Sriniketh24 Converting to draft — this PR doesn't yet meet our Pull Request quality criteria.
See the linked criteria for how to fix each item, then mark the PR "Ready for review". This is not a rejection — just an invitation to bring the PR up to standard. No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. Drafted-by: Claude Code (Opus 4.7); reviewed by @potiuk before posting |
dumps() must return bytes because flask-session stores the serialized data in a LargeBinary (BLOB) column. The previous commit incorrectly returned str which caused a TypeError on INSERT. Keep the JSON encoding format (instead of the original msgpack) for readability and forward compatibility, with backward-compatible loads() that falls back to msgpack for legacy sessions.
Summary
Switch
_LazySafeSerializerfrommsgspec.msgpacktomsgspec.jsonfor the database session backend. JSON is human-readable (easier to debug session data in the database) and more widely compatible. The serializer continues to returnbytesas required by flask-session'sLargeBinarycolumn.The
loads()method tries JSON first and falls back to msgpack, so existing sessions written in msgpack format are read transparently without requiring migration.related: #64921
Changes
providers/fab/src/airflow/providers/fab/www/session.py: Switch_LazySafeSerializerfrommsgspec.msgpacktomsgspec.jsonencoding.loads()now tries JSON first and falls back to msgpack for legacy session data. Returnsbytesfor theLargeBinarydatabase column.providers/fab/tests/unit/fab/www/test_session.py: Add 8 tests covering bytes return type, roundtrip, LazyString conversion, legacy msgpack backward compatibility, empty session, nested data, encode/decode aliases, and str/bytes input handling.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.6) following the guidelines