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: prevent CastError being triggered by literal NaN #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jdbdnz
Copy link

@jdbdnz jdbdnz commented Aug 9, 2023

Overview

NaN is a valid value in MongoDB for Number type attributes (i.e. doubles). This change is necessary to avoid superfluous errors when loading records with NaN values in number fields.

Previous behavior:

  • "harold" => CastError
  • NaN => CastError
  • 1 => no error

New behavior:

  • "harold" => CastError
  • NaN => no error
  • 1 => no error

Changes

  • change the conditions for CastError to throw for anything which resolves to a NaN, but not for literal NaNs

Thoughts

I think the decision to accept NaN as a valid number type in MongoDB is dubious, I don't see a valid reason for wanting to store it. That said, the world is imperfect and so is the data we deal with.

My judgement here is that it is better to handle the imperfections gracefully. Feel free to close if you don't agree, and I'll just keep using my fork.

@jdbdnz jdbdnz changed the title fix: allow NaNs fix: prevent CastError being triggered by literal NaN Aug 9, 2023
@jdbdnz
Copy link
Author

jdbdnz commented Aug 9, 2023

I could see a case being made for removing the CastError entirely; instead writing non-numbers as NaN. I don't want to make it though.

@jdbdnz
Copy link
Author

jdbdnz commented Jun 17, 2024

@vkarpov15 are you interested in this change, or should I close this?

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.

1 participant