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

Fix encoding/decoding for OrjsonField #61

Merged
merged 1 commit into from
Mar 31, 2022
Merged

Conversation

MarkKoz
Copy link
Collaborator

@MarkKoz MarkKoz commented Mar 10, 2022

The encoder and decoder are expected to be objects following the JSONEncoder and JSONDecoder interfaces, respectively. Thus, the orjson dumps and loads functions cannot be used directly.

Define JSONEncoder and JSONDecoder subclasses which wrap orjson, and use these as the encoder and decoder for OrjsonField.

This field was only used by the /api/notification_settings/ settings endpoint, so that endpoint should now be able to work. Previously, it always reported a JSON validation error for the condition field. To test it, the following code can be used

(async () => {
    let response = await fetch(
        "/api/notification_settings/",
        {
            method: "POST",
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'X-CSRFToken': getCookie('csrftoken'),
            },
            mode: 'same-origin',
            body: JSON.stringify({
                condition: {"var": 1},
                destination: ["EM", "WE"],
                test: 1, // This test needs to be created beforehand
                message: "hello"
            }),
        }
    );
    let content = await response.json();
    console.log(content);
})();

The encoder and decoder are expected to be objects following the
JSONEncoder and JSONDecoder interfaces, respectively. Thus, the orjson
dumps and loads functions cannot be used directly.

Define JSONEncoder and JSONDecoder subclasses which wrap orjson, and
use these as the encoder and decoder for OrjsonField.
@MarkKoz MarkKoz added t: bug Something isn't working a: backend labels Mar 10, 2022
@MarkKoz MarkKoz enabled auto-merge March 29, 2022 20:00
mndzamel
mndzamel previously approved these changes Mar 30, 2022
@MarkKoz MarkKoz disabled auto-merge March 31, 2022 20:06
@MarkKoz MarkKoz merged commit 14dd703 into main Mar 31, 2022
@MarkKoz MarkKoz deleted the bug/back/orjson-field branch March 31, 2022 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: backend t: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants