[GH-ISSUE #37] sqlalchemy_utils.PasswordType makes JSONEncoder's serialization barf #24

Closed
opened 2026-02-26 01:32:55 +03:00 by kerem · 3 comments
Owner

Originally created by @Datamance on GitHub (Jul 31, 2016).
Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/37

Here's my stacktrace:

  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/json.py", line 83, in default
    return _json.JSONEncoder.default(self, o)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'$2a$12$0rN/M0JPI3ChHNlxBnhoqeNyaC95otDUbflNsjY5O9XvEAlLiUETi' is not JSON serializable

You just might wanna make the api machinery a little more robust, to handle bytes serialization.

Originally created by @Datamance on GitHub (Jul 31, 2016). Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/37 Here's my stacktrace: ``` File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/json.py", line 83, in default return _json.JSONEncoder.default(self, o) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/encoder.py", line 173, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: b'$2a$12$0rN/M0JPI3ChHNlxBnhoqeNyaC95otDUbflNsjY5O9XvEAlLiUETi' is not JSON serializable ``` You just might wanna make the api machinery a little more robust, to handle bytes serialization.
kerem 2026-02-26 01:32:55 +03:00
Author
Owner

@jeffknupp commented on GitHub (Jul 31, 2016):

JSON, as a format, does not have a way to encode arbitrary binary data. That's a limit of the format, not the API.

<!-- gh-comment-id:236436319 --> @jeffknupp commented on GitHub (Jul 31, 2016): JSON, as a format, does not have a way to encode arbitrary binary data. That's a limit of the format, not the API.
Author
Owner

@Datamance commented on GitHub (Jul 31, 2016):

@jeffknupp then maybe have default serialization for binary data properties turned off? I'm guessing that you're going to have other devs who want to get user data from databases that use bcrypt to protect passwords.

I'm assuming this is something I can get around by extending sandman2.model.Model?

<!-- gh-comment-id:236464338 --> @Datamance commented on GitHub (Jul 31, 2016): @jeffknupp then maybe have default serialization for binary data properties turned off? I'm guessing that you're going to have other devs who want to get user data from databases that use bcrypt to protect passwords. I'm assuming this is something I can get around by extending sandman2.model.Model?
Author
Owner

@jeffknupp commented on GitHub (Aug 5, 2016):

Yes, the proper way to address this would be to extend sandman2.model.Model. I'm 👎 on excluding types from serialization as it would either require a catch-all rule that would be difficult to maintain or an explicit list of (database-specific) excluded types which would be even more error-prone.

<!-- gh-comment-id:237955082 --> @jeffknupp commented on GitHub (Aug 5, 2016): Yes, the proper way to address this would be to extend `sandman2.model.Model`. I'm 👎 on excluding types from serialization as it would either require a catch-all rule that would be difficult to maintain or an explicit list of (database-specific) excluded types which would be even more error-prone.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/sandman2-jeffknupp#24
No description provided.