Skip to content
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

Flash message with Markup fails #272

Open
jeroen-80 opened this issue Dec 10, 2024 · 0 comments
Open

Flash message with Markup fails #272

jeroen-80 opened this issue Dec 10, 2024 · 0 comments

Comments

@jeroen-80
Copy link

Upgrading my platform from Python 3.8 + Flask 3.0.3 + Flask-Session 0.8.0 with redis backend, to Python 3.11 + Flask 3.1.0 + Flask-Session 0.8.0 with redis backend. Same user code.

Issue: fancy flash message breaks on the new platform (work fine on the old platform).

Flash message:
flash(Markup('press the play button <i class="bi-play-btn-fill black"></i> below'), 'info')

Error:

[2024-12-10 19:01:28,998] ERROR in base: Failed to serialize session data: Encoding objects of type Markup is unsupported
[2024-12-10 19:01:28,998] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 920, in full_dispatch_request
    return self.finalize_request(rv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 941, in finalize_request
    response = self.process_response(response)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 1322, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/var/www/lib/python3.11/site-packages/flask_session/base.py", line 305, in save_session
    self._upsert_session(app.permanent_session_lifetime, session, store_id)
  File "/var/www/lib/python3.11/site-packages/flask_session/redis/redis.py", line 78, in _upsert_session
    serialized_session_data = self.serializer.encode(session)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask_session/base.py", line 132, in encode
    return self.encoder.encode(dict(session))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Encoding objects of type Markup is unsupported
[2024-12-10 19:01:29,002] ERROR in base: Failed to serialize session data: Encoding objects of type Markup is unsupported
[2024-12-10 19:01:29,002] ERROR in app: Request finalizing failed with an error while handling an error
Traceback (most recent call last):
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 920, in full_dispatch_request
    return self.finalize_request(rv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 941, in finalize_request
    response = self.process_response(response)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 1322, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/var/www/lib/python3.11/site-packages/flask_session/base.py", line 305, in save_session
    self._upsert_session(app.permanent_session_lifetime, session, store_id)
  File "/var/www/lib/python3.11/site-packages/flask_session/redis/redis.py", line 78, in _upsert_session
    serialized_session_data = self.serializer.encode(session)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask_session/base.py", line 132, in encode
    return self.encoder.encode(dict(session))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Encoding objects of type Markup is unsupported

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 941, in finalize_request
    response = self.process_response(response)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask/app.py", line 1322, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/var/www/lib/python3.11/site-packages/flask_session/base.py", line 305, in save_session
    self._upsert_session(app.permanent_session_lifetime, session, store_id)
  File "/var/www/lib/python3.11/site-packages/flask_session/redis/redis.py", line 78, in _upsert_session
    serialized_session_data = self.serializer.encode(session)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/lib/python3.11/site-packages/flask_session/base.py", line 132, in encode
    return self.encoder.encode(dict(session))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Encoding objects of type Markup is unsupported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant