serializable_hash(only: []) should exclude all fields

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 9.1.0
    • Affects Version/s: 9.0.8, 8.1.12
    • Component/s: None
    • None
    • 🔵 Done
    • Ruby Drivers
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?

      The serializable_hash method, when passed an empty array for the ":only" option, previously would return all keys. This ticket adds a new configuration option "Mongoid::Config. serializable_hash_with_legacy_only", which defaults to true. When true, Mongoid uses the pre-existing legacy behavior. When this flag is false, passing an empty array to the ":only" option will cause the method to return an empty hash.

      Beginning in Mongoid 10, the legacy behavior will be deprecated, and will be removed entirely in Mongoid 11.

      2. Would you like the user to see examples of the syntax and/or executable code and its output?

      Not necessary.

      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? The serializable_hash method, when passed an empty array for the ":only" option, previously would return all keys. This ticket adds a new configuration option "Mongoid::Config. serializable_hash_with_legacy_only", which defaults to true. When true, Mongoid uses the pre-existing legacy behavior. When this flag is false, passing an empty array to the ":only" option will cause the method to return an empty hash. Beginning in Mongoid 10, the legacy behavior will be deprecated, and will be removed entirely in Mongoid 11. 2. Would you like the user to see examples of the syntax and/or executable code and its output? Not necessary. 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      When serializable_hash is called with only: [], it results in all fields being included, rather than excluding everything. This behavior has been in place since 2012, but it is confusing.

      Brad Pardee has created a PR to address this here: https://github.com/mongodb/mongoid/pull/6031

      Because this behavior has been in place for so long, we prefer to move carefully here and assume that changing the behavior may potentially break some existing applications. Thus, we should introduce a feature flag (default false) that enables the new behavior, change the default to true in the next major version (Mongoid 10), and finally remove the flag in the next major version after that (e.g. Mongoid 11).

            Assignee:
            Unassigned
            Reporter:
            Jamis Buck
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: