Skip to content

Conversation

@Mantisus
Copy link
Collaborator

@Mantisus Mantisus commented Nov 12, 2024

Description

An incorrect serialization for payload is happening now. payload is represented as a byte string, but bytes cannot be serialized to json. Therefore, when loading and unloading from the queue (_persist_single_request_to_storage, _json_to_request) we get strings of format “b'test'”

Also corrected the documentation, as when filling forms the data should be passed not in json format and have the appropriate header.

Issues

Testing

Updated test_request_state_serialization to also take payload into account when serializing and deserializing Request

Checklist

  • CI passed

@vdusek vdusek added this to the 102nd sprint - Tooling team milestone Nov 12, 2024
@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. bug Something isn't working. labels Nov 12, 2024
Copy link
Collaborator

@vdusek vdusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got just stylistic things... We already discussed it directly, but we should make sure this is going to work on the platform. Let me know once it is tested. Thank you.

@janbuchar
Copy link
Collaborator

Thanks @Mantisus! Could you please add a test that shows that the bug has been fixed?

Copy link
Collaborator

@vdusek vdusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, otherwise LGTM, thanks.

@vdusek vdusek merged commit e8b4d2d into apify:master Nov 12, 2024
23 checks passed
Copy link
Collaborator

@janbuchar janbuchar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see a test case that would prove that #668 is resolved. It might be necessary to test that on HttpClient level.

payload: Annotated[
HttpPayload | None,
BeforeValidator(lambda v: v.encode() if isinstance(v, str) else v),
PlainSerializer(lambda v: v.decode() if isinstance(v, bytes) else None),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is scary - could you return v in the else branch instead?

got_request = await request_queue_client.get_request(request.id)

assert request == got_request
assert request.payload == got_request.payload
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comparison is part of Request.__eq__, so this assertion accomplishes nothing.

@Mantisus
Copy link
Collaborator Author

Mantisus commented Nov 12, 2024

I still don't see a test case that would prove that #668 is resolved. It might be necessary to test that on HttpClient level.

The problem in #668 is due to the fact that after serialization-deserialization payload does not match, b “test” becomes b “b'test'”. We can add a test to check this case specifically.

But in essence, it is sufficient.

assert request == got_request

All the other problems described in #668 are related to incorrectly created payload for the Request.

vdusek pushed a commit that referenced this pull request Nov 14, 2024
### Description

Correction of comments related to  PR #683
Add new tests for `http_crawler` different forms of `payload`

### Testing

The test checks that the `payload` on the client side matches the data
received by the server.
Also added verification that different types of `payload` are correctly
handled on the client side and correctly recognized by the server with
appropriate headers

### Checklist

- [x] CI passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issues with payload in POST requests

3 participants