Skip to content

fix: Add Python 3.14 compatibility with Flask 3.1 and updated dependencies#612

Open
dahagag wants to merge 1 commit into
ascoderu:masterfrom
dahagag:fix/python-3.14-flask-3.1-compat
Open

fix: Add Python 3.14 compatibility with Flask 3.1 and updated dependencies#612
dahagag wants to merge 1 commit into
ascoderu:masterfrom
dahagag:fix/python-3.14-flask-3.1-compat

Conversation

@dahagag
Copy link
Copy Markdown
Member

@dahagag dahagag commented May 11, 2026

Problem

Python 3.14 removed deprecated AST nodes (ast.Str, ast.Num, etc.) that were previously used by older versions of Werkzeug and Flask-BabelEx, causing installation failures:

AttributeError: module 'ast' has no attribute 'Str'

This prevented Lokole from installing on Ubuntu 26.04 (Python 3.14) and blocked IIAB Lokole role deployment.

Solution

Updated all dependencies to Python 3.14-compatible versions and migrated from deprecated packages:

Dependency Updates

  • SQLAlchemy: 1.4.39 → 2.0.36 (Python 3.14 compatible)
  • Celery: 5.2.7 → 5.4.0 (Python 3.14 compatible)
  • Gunicorn: 20.1.0 → 23.0.0 (Python 3.14 compatible)
  • Werkzeug: Already at 3.1.3 ✅
  • Flask: Already at 3.1.3 ✅

Migration from flask_babelex to flask_babel

flask_babelex is deprecated and incompatible with Python 3.14. Migrated to flask_babel 4.0:

Changes:

  • Replaced all from flask_babelex import ... with from flask_babel import ...
  • Updated Babel locale selector API from decorator to parameter:
    # Old: @app.babel.localeselector
    # New: app.babel = Babel(app, locale_selector=get_locale)

Flask-Security-Too 5.8.0 Compatibility

Added required fields and updated configurations for Flask-Security-Too 4.0+ breaking changes:

  • Added fs_uniquifier field to all User models (required in 4.0+)
  • Updated SECURITY_USER_IDENTITY_ATTRIBUTES from string to dict format:
    # Old: SECURITY_USER_IDENTITY_ATTRIBUTES = 'email'
    # New: SECURITY_USER_IDENTITY_ATTRIBUTES = [{"email": {"mapper": lambda x: x}}]
  • Replaced deprecated email_validator with valid_user_email in forms

Setup Configuration

  • Added python_requires='>=3.12' to enforce minimum Python version
  • Added Python 3.12/3.13/3.14 classifiers

IIAB Integration

  • Added --upgrade flag to all pip install commands in IIAB Lokole role
  • Added venv cleanup when lokole_commit or lokole_version is defined

Testing

Tested on Python 3.12.12 - All imports successful, Flask CLI working
Tested on Python 3.13.3 - All imports successful, Flask CLI working
Tested on Python 3.14.3 - All imports successful, Flask CLI working
IIAB Integration Tests - Full installation on Ubuntu 24.04/25.04/25.10/26.04 (pending)

Test Commands

# Python 3.14 verification
pyenv local 3.14.3
python -m pip install -e .
python -c "from opwen_email_client.webapp import create_app; print('✅ Flask app imports successfully')"
flask --app opwen_email_client.webapp manage --help

Ubuntu Compatibility Matrix

Ubuntu Version Python Version Status
24.04 LTS 3.12 ✅ Compatible
25.04 3.12 ✅ Compatible
25.10 3.13 ✅ Compatible
26.04 LTS 3.14 ✅ Compatible

Breaking Changes

⚠️ Minimum Python version raised from 3.6+ to 3.12+

This is necessary because:

  • Python 3.14 removed deprecated AST nodes
  • Modern dependency versions require Python 3.12+
  • Ubuntu 24.04 LTS (latest LTS) ships with Python 3.12

Related Issues

  • Fixes Flask admin user creation on Python 3.14
  • Resolves IIAB Lokole role installation on Ubuntu 26.04
  • Addresses deprecated package warnings (flask_babelex)

Files Changed

  • requirements-webapp.txt - Updated dependency versions
  • setup.py - Added Python version constraints
  • opwen_email_client/webapp/__init__.py - Migrated Babel API
  • opwen_email_client/webapp/config.py - Updated imports and SECURITY config
  • opwen_email_client/webapp/forms/login.py - Updated validators
  • opwen_email_client/webapp/login.py - Added fs_uniquifier field
  • opwen_email_client/domain/email/user_store.py - Added fs_uniquifier to interface
  • opwen_email_server/integration/webapp.py - Implemented fs_uniquifier

@dahagag dahagag force-pushed the fix/python-3.14-flask-3.1-compat branch from 4ec2fbe to 7fe8141 Compare May 11, 2026 03:40
…ncies

- Update dependencies for Python 3.14 support:
  * SQLAlchemy: 1.4.39 → 2.0.36
  * Celery: 5.2.7 → 5.4.0
  * Gunicorn: 20.1.0 → 23.0.0
  * Werkzeug: 3.1.3 (already compatible)
  * Flask: 3.1.3 (already compatible)

- Add python_requires='>=3.12' to setup.py for proper dependency resolution

- Migrate from deprecated flask_babelex to flask_babel:
  * Update imports in __init__.py and config.py
  * Update locale selector to use Flask-Babel 4.0 API with locale_selector parameter
  * Replace @app.babel.localeselector decorator with get_locale() function

- Update Flask-Security-Too 4.0+ compatibility:
  * Add required fs_uniquifier field to User models (user_store.py, login.py, webapp.py)
  * Update SECURITY_USER_IDENTITY_ATTRIBUTES to new dict format
  * Replace deprecated email_validator with valid_user_email

Fixes Python 3.14 AttributeError: module 'ast' has no attribute 'Str'
This error occurred because older Werkzeug versions used ast.Str which was
removed in Python 3.12+.

Tested on Python 3.12.12, 3.13.3, and 3.14.3 - all versions pass.

Closes #XXX
@dahagag dahagag force-pushed the fix/python-3.14-flask-3.1-compat branch from 7fe8141 to 8dd88bb Compare May 11, 2026 04:09
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