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 null value parsing #1668

Merged
merged 8 commits into from
Sep 12, 2024
Merged

Fix null value parsing #1668

merged 8 commits into from
Sep 12, 2024

Conversation

dustin-H
Copy link
Contributor

@dustin-H dustin-H commented Sep 11, 2024

Hi there,

first of all, I really like your project! Amazing work! 🚀
Thank you!

While integrating it I found a bug:
When a shape includes a column, that is nullable and currently null or set to null, the typescript client is crashing:

Screenshot 2024-09-11 at 07 20 16

The code is checking if the typeof value is object and is then trying to iterate over it's keys.
However, typeof null is also object. This is why it crashes here, as it cannot iterate over null.
This PR fixes #1673.

A simple check for null fixes this as proposed in this PR.

Could you please merge it? Or is there anything I've overseen?
Thanks!

@KyleAMathews
Copy link
Contributor

Hey thanks for reporting and fixing the issue!

Could you also add a test for the issue? Lemme know if you need help running the tests. The contribution docs are immature still.

@dustin-H
Copy link
Contributor Author

@KyleAMathews Thanks for your quick reply.

I just wrote a test, made the check more precise and added a comment to explain why the check for null is required.

If you run the test without my change, it will fail with the error posted above.

Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

Hi @dustin-H,

Thanks for contributing this PR.
After taking a closer look, i think the test is wrong (see my comment there) because the message is ill-formed. As a result, the fix is fixing something that cannot occur.

You're referring to a bug:

While integrating it I found a bug:
When a shape includes a column, that is nullable and currently null or set to null, the typescript client is crashing

Could you open an issue with a reproduction for this please?
We have unit tests that check that null values are parsed correctly, but perhaps we are missing a corner case. Feel free to contribute that test case if you want.

packages/typescript-client/test/parser.test.ts Outdated Show resolved Hide resolved
@dustin-H
Copy link
Contributor Author

Hi @kevin-dp,

you are right. I accidentally created the test with an invalid message, which led to the same result as the correct one.

I created the issue you requested: #1673

I also fixed the test to match the message I mean.

@kevin-dp
Copy link
Contributor

Fixes #1673.

@dustin-H dustin-H requested a review from kevin-dp September 12, 2024 07:25
Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

Thank you for contributing the test case we were missing for columns named "value" and providing the fix 💯

@kevin-dp kevin-dp merged commit 412ea8e into electric-sql:main Sep 12, 2024
24 checks passed
KyleAMathews pushed a commit that referenced this pull request Nov 1, 2024
Hi there,

first of all, I really like your project! Amazing work! 🚀 
Thank you!

While integrating it I found a bug:
When a shape includes a column, that is nullable and currently null or
set to null, the typescript client is crashing:

<img width="637" alt="Screenshot 2024-09-11 at 07 20 16"
src="https://github.com/user-attachments/assets/0667fcc4-aa32-4a2f-9d29-3866fc1e53bc">

The code is checking if the `typeof value` is `object` and is then
trying to iterate over it's keys.
However, `typeof null` is also `object`. This is why it crashes here, as
it cannot iterate over null.
This PR fixes #1673.

A simple check for `null` fixes this as proposed in this PR.

Could you please merge it? Or is there anything I've overseen?
Thanks!

---------

Co-authored-by: Kevin De Porre <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS Client crashes when a column named value is null
3 participants