Base64 encode serialized jobs when using Postgres #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #42
This PR fixes a bug where serializing workflow jobs with private properties could lead to truncated data being saved when using Postgresql.
Since we serialize and unserialize workflow jobs in multiple places (the
Workflow
model, as well as theUnserializeWorkflowJobExtractor
), I decided to separate this logic out into a separate class so it isn't duplicated all over the place.In short, when serializing workflow job, we check if we’re using a
PostgresConnection
and if sobase64_encode
the serialized string before storing it. This gets rid of any null bytes in the serialized string so Postgres doesn’t treat it as a null-terminated string anymore. We do the inverse when unserializing jobs. To ensure backwards compatibility, we don'tbase64_decode
a string if it doesn't contain:
or;
. We use this as a heuristic to check if we're dealing with a base64 encoded string or not since these characters will never appear in a base64 encoded string. This implementation is based on the PR which fixes the same bug in Laravel’s queue system (laravel/framework#36081).I haven’t added a separate test to test for this specific bug, as adding configuring a Postgres database in our CI pipeline just for a single test seemed a little excessive. I did, however, reproduce the bug locally and confirmed that these changes fix the bug. I used the example repository provided in #42 as starting point.
As far as I can tell, this change should be backwards compatible and should not require a major version bump.