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

cannot use a string pattern on a bytes-like object #29695

Closed
3 tasks
ylq5126 opened this issue Jul 25, 2024 · 6 comments
Closed
3 tasks

cannot use a string pattern on a bytes-like object #29695

ylq5126 opened this issue Jul 25, 2024 · 6 comments

Comments

@ylq5126
Copy link

ylq5126 commented Jul 25, 2024

Bug description

use redis to store session, server not start current

How to reproduce the bug

from docker file 4.0.2-dev

config use
SESSION_SERVER_SIDE = True
SESSION_TYPE = "redis"
SESSION_REDIS = Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_SESSION_DB, password=REDIS_PASS, charset="utf-8")

in docker flask-session is 0.5.0

image

Screenshots/recordings

superset-prod-01 | Exception on / [GET]
superset-prod-01 | Traceback (most recent call last):
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
superset-prod-01 | response = self.full_dispatch_request()
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
superset-prod-01 | return self.finalize_request(rv)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
superset-prod-01 | response = self.process_response(response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
superset-prod-01 | self.session_interface.save_session(self, ctx.session, response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 164, in save_session
superset-prod-01 | response.set_cookie(app.config["SESSION_COOKIE_NAME"], session_id,
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/sansio/response.py", line 224, in set_cookie
superset-prod-01 | dump_cookie(
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/http.py", line 1303, in dump_cookie
superset-prod-01 | if not _cookie_no_quote_re.fullmatch(value):
superset-prod-01 | TypeError: cannot use a string pattern on a bytes-like object
superset-prod-01 | 2024-07-17 12:20:45,421:ERROR:superset.app:Exception on / [GET]
superset-prod-01 | Traceback (most recent call last):
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
superset-prod-01 | response = self.full_dispatch_request()
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
superset-prod-01 | return self.finalize_request(rv)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
superset-prod-01 | response = self.process_response(response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
superset-prod-01 | self.session_interface.save_session(self, ctx.session, response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 164, in save_session
superset-prod-01 | response.set_cookie(app.config["SESSION_COOKIE_NAME"], session_id,
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/sansio/response.py", line 224, in set_cookie
superset-prod-01 | dump_cookie(
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/http.py", line 1303, in dump_cookie
superset-prod-01 | if not _cookie_no_quote_re.fullmatch(value):
superset-prod-01 | TypeError: cannot use a string pattern on a bytes-like object
superset-prod-01 | Request finalizing failed with an error while handling an error
superset-prod-01 | Traceback (most recent call last):
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
superset-prod-01 | response = self.full_dispatch_request()
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
superset-prod-01 | return self.finalize_request(rv)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
superset-prod-01 | response = self.process_response(response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
superset-prod-01 | self.session_interface.save_session(self, ctx.session, response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 164, in save_session
superset-prod-01 | response.set_cookie(app.config["SESSION_COOKIE_NAME"], session_id,
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/sansio/response.py", line 224, in set_cookie
superset-prod-01 | dump_cookie(
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/http.py", line 1303, in dump_cookie
superset-prod-01 | if not _cookie_no_quote_re.fullmatch(value):
superset-prod-01 | TypeError: cannot use a string pattern on a bytes-like object
superset-prod-01 |
superset-prod-01 | During handling of the above exception, another exception occurred:
superset-prod-01 |
superset-prod-01 | Traceback (most recent call last):
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
superset-prod-01 | response = self.process_response(response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
superset-prod-01 | self.session_interface.save_session(self, ctx.session, response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 164, in save_session
superset-prod-01 | response.set_cookie(app.config["SESSION_COOKIE_NAME"], session_id,
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/sansio/response.py", line 224, in set_cookie
superset-prod-01 | dump_cookie(
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/http.py", line 1303, in dump_cookie
superset-prod-01 | if not _cookie_no_quote_re.fullmatch(value):
superset-prod-01 | TypeError: cannot use a string pattern on a bytes-like object
superset-prod-01 | 2024-07-17 12:20:45,423:ERROR:superset.app:Request finalizing failed with an error while handling an error
superset-prod-01 | Traceback (most recent call last):
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
superset-prod-01 | response = self.full_dispatch_request()
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
superset-prod-01 | return self.finalize_request(rv)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
superset-prod-01 | response = self.process_response(response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
superset-prod-01 | self.session_interface.save_session(self, ctx.session, response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 164, in save_session
superset-prod-01 | response.set_cookie(app.config["SESSION_COOKIE_NAME"], session_id,
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/sansio/response.py", line 224, in set_cookie
superset-prod-01 | dump_cookie(
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/http.py", line 1303, in dump_cookie
superset-prod-01 | if not _cookie_no_quote_re.fullmatch(value):
superset-prod-01 | TypeError: cannot use a string pattern on a bytes-like object
superset-prod-01 |
superset-prod-01 | During handling of the above exception, another exception occurred:
superset-prod-01 |
superset-prod-01 | Traceback (most recent call last):
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
superset-prod-01 | response = self.process_response(response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
superset-prod-01 | self.session_interface.save_session(self, ctx.session, response)
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 164, in save_session
superset-prod-01 | response.set_cookie(app.config["SESSION_COOKIE_NAME"], session_id,
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/sansio/response.py", line 224, in set_cookie
superset-prod-01 | dump_cookie(
superset-prod-01 | File "/usr/local/lib/python3.9/site-packages/werkzeug/http.py", line 1303, in dump_cookie
superset-prod-01 | if not _cookie_no_quote_re.fullmatch(value):
superset-prod-01 | TypeError: cannot use a string pattern on a bytes-like object
superset-prod-01 | 10.100.138.2 - - [17/Jul/2024:12:20:45 0000] "GET / HTTP/1.1" 500 332 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"

Superset version

4.0.2

Python version

3.9

Node version

16

Browser

Chrome

Additional context

from werkzeug issue
pallets/werkzeug#2795
from flask-session Changes
https://flask-session.readthedocs.io/en/latest/changes.html#id1

flask-session not supported werkzeug 3.0 when version less than 0.6.0

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
@ylq5126 ylq5126 mentioned this issue Jul 25, 2024
3 tasks
Copy link

dosubot bot commented Jul 25, 2024

Hey @ylq5126! I'm here to help you out with any bugs, questions, or contributions you might have. Let's work together to solve this issue!

The TypeError: cannot use a string pattern on a bytes-like object error you're encountering is due to an incompatibility between Flask-Session 0.5.0 and Werkzeug 3.0.0. Flask-Session versions prior to 0.6.0 do not support Werkzeug 3.0.0, which causes this issue when setting cookies.

To resolve this, you should upgrade Flask-Session to at least version 0.6.0, which includes support for Werkzeug 3.0.0. You can do this by updating your requirements.txt or pyproject.toml file to specify the newer version of Flask-Session.

Here is an example of how you can update your requirements.txt:

Flask-Session>=0.6.0

Or if you are using pyproject.toml:

[tool.poetry.dependencies]
flask-session = ">=0.6.0"

After updating the dependency, make sure to reinstall the packages:

pip install -r requirements.txt
# or
poetry install

This should resolve the TypeError and allow your server to start correctly with Redis for session management [1].

To continue talking to Dosu, mention @dosu.

@meghana1911
Copy link

@ylq5126 Did this work for you. What changes did you make?

@ylq5126
Copy link
Author

ylq5126 commented Aug 7, 2024

@ylq5126 Did this work for you. What changes did you make?
pip install flask-session==0.8.0

@ylq5126
Copy link
Author

ylq5126 commented Aug 7, 2024

@ylq5126 Did this work for you. What changes did you make?

update version to 4.1.x

@patheard
Copy link

Confirmed this fixed for us as well on v4.0.2.

@rusackas
Copy link
Member

Sounds like this is solved for 4.0 and 4.1, so I'll go ahead and close this out. Please let me know if I've misjudged and I/we can reopen it :)

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

No branches or pull requests

4 participants