[16.0][IMP] session_db: Modify the way to parse data from session data#3497
[16.0][IMP] session_db: Modify the way to parse data from session data#3497JonathanOsAlc wants to merge 1 commit intoOCA:16.0from
Conversation
|
Hi @sbidoul, |
5c49968 to
3c70bb6
Compare
|
Hello and thanks for contributing! To help me understand your PR, can you elaborate the problem you are addressing? In particular do they also occur with the standard Odoo session or only with session_db? Do they occur with standard Odoo modules or custom code? Can you also elaborate what the problem with debug=1, as I personally never noticed any problem in debug mode with session_db. |
3c70bb6 to
fe13fc4
Compare
When a custom module temporarily stores binary data (like images) in the user's session, `session_db` crashes with a `TypeError: Object of type bytes is not JSON serializable`. This happens because `session_db` explicitly calls `json.dumps()` to store the session payload in PostgreSQL. - Introduced a recursive helper `_traverse_and_convert` using dictionary comprehensions to traverse the session payload safely. - Binary values (`bytes`) are converted to base64 strings with a `base64::` prefix before JSON serialization (`session_to_str`). - When loading the session from the DB, `str_to_session` identifies the prefix and converts the string back to `bytes`.
fe13fc4 to
96cfe0f
Compare
|
Hello, and thank you for taking the time to review this PR! I have made modifications to the code and updated the PR description to be much more detailed. After reviewing the again the issue, I realized that the logic handling int/float conversions and the debug=1 parameter was unnecessary. This PR is now focused on fixing the JSON serialization crash for binary (bytes) data. To answer your specific questions:
This crash specifically occurs when using
The specific trigger comes from a custom module. We have a "preview" feature that temporarily stores form data (which includes image binaries) in the user's session (request.session) to avoid creating unnecessary records in the database before the user confirms. While triggered by custom code, putting binary data in the session is a valid approach, and installing
You are absolutely right—there is no inherent problem with debug=1 in session_db. The issue I mentioned in previous commits was actually caused by my own attempt to parse ints/floats (which accidentally converted the "debug": "1" string into an integer). Since I have dropped that int/float logic completely, the debug mode works perfectly without any extra changes. I have updated the main PR description with the traceback and the technical implementation of the base64 fix. I will also be attaching evidence shortly showing the error and how this patch resolves it. Let me know if the updated code and scope look good to you! |
Summary
This PR fixes a error traceback occurring in the
session_dbmodule whenbytesobjects are present in the Odoo session (request.session).When custom modules place binary data in the session (e.g., for temporary image previews before saving a record), the
pg_session_store.pyscript crashes during thejson.dumps(dict(session))call because the standardjsoncannot serializebytesobjects natively.Traceback Resolved
Technical Implementation
base64::.Evidence
Video: https://drive.google.com/file/d/1M3T3rBrKN4jcU2t-zuxDcViyrPwlnn20/view?usp=sharing
Video: https://drive.google.com/file/d/1V6eztsmkGEGkQaJoD725aVlrvE06XLuO/view