Skip to content

Add error raise for deep_symbolize_keys! #346

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

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

Conversation

IvanTakarlikov-st
Copy link

Overview

Analogue of this PR but for `.deep_symbolize_keys!'

Inspired by few hours debugging why things behave weird

[DEVELOPMENT] tags/master-build-29117^0 irb(main):001:0> d = BSON::Document.new(foo: 'bar')
=> {"foo"=>"bar"}
[DEVELOPMENT] tags/master-build-29117^0 irb(main):002:0> d.deep_symbolize_keys!
=> {"foo"=>"bar"}
[DEVELOPMENT] tags/master-build-29117^0 irb(main):003:0> d.symbolize_keys!
(irb):3:in `<main>': symbolize_keys! is not supported on BSON::Document instances. Please convert the document to hash first (using #to_h), then call #symbolize_keys! on the Hash instance (ArgumentError)

It will be also great to backport it to 4 major, I can create PR if you'll accept this one.

@IvanTakarlikov-st IvanTakarlikov-st requested a review from a team as a code owner April 18, 2025 18:01
@IvanTakarlikov-st IvanTakarlikov-st requested review from jamis and removed request for a team April 18, 2025 18:01
@jamis
Copy link
Contributor

jamis commented Apr 21, 2025

Great catch, @IvanTakarlikov-st , and thank you very much for the pull request.

Even though this is the right thing to do, it still represents a breaking change. Whether it was intentional or not, #deep_symbolize_keys! is currently a part of the public API. Per semantic versioning constraints, this change will need to be part of a new major version of the library (v6.0.0).

I propose the following:

  1. Change this PR so it issues a deprecation warning if BSON::Document#deep_symbolize_keys! is called.
  2. Create a ticket in Jira that will raise the error as you've done here, as part of an eventual ruby-bson 6.0.0 release.

I can create the Jira ticket, if you'll adjust this PR to warn instead of raise.

@IvanTakarlikov-st
Copy link
Author

Great catch, @IvanTakarlikov-st , and thank you very much for the pull request.

Even though this is the right thing to do, it still represents a breaking change. Whether it was intentional or not, #deep_symbolize_keys! is currently a part of the public API. Per semantic versioning constraints, this change will need to be part of a new major version of the library (v6.0.0).

I propose the following:

  1. Change this PR so it issues a deprecation warning if BSON::Document#deep_symbolize_keys! is called.
  2. Create a ticket in Jira that will raise the error as you've done here, as part of an eventual ruby-bson 6.0.0 release.

I can create the Jira ticket, if you'll adjust this PR to warn instead of raise.

It makes a total sense to me, I'll adjust it to be warning.

@jamis
Copy link
Contributor

jamis commented Apr 23, 2025

JIRA ticket here: https://jira.mongodb.org/browse/RUBY-3656

@IvanTakarlikov-st
Copy link
Author

Updated the behaviour to print warn, not raising error.

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.

2 participants