WA-NEW-010: Eliminate BSON Symbol deprecation warning in test suite#635
Open
kitcommerce wants to merge 1 commit intonextfrom
Open
WA-NEW-010: Eliminate BSON Symbol deprecation warning in test suite#635kitcommerce wants to merge 1 commit intonextfrom
kitcommerce wants to merge 1 commit intonextfrom
Conversation
mongoid-audit_log defines `field :action, type: Symbol` in its Entry
model. BSON 5.x deprecates the BSON Symbol wire type (0x0E) and Mongoid
7.4.x emits a one-time warning whenever such a field is registered, which
pollutes every test run.
Fix (two parts):
1. freedom_patches/mongoid_audit_log.rb — pre-set Mongoid's
one-time-warned flag before `require 'mongoid/audit_log'` so the
gem's own field definition no longer triggers the warning.
2. ext/mongoid/audit_log_entry.rb — re-declare `action` as
`type: String, overwrite: true` in our existing decorator so new
audit-log entries store a plain UTF-8 string instead of the deprecated
BSON Symbol type. A custom #action reader returns `super&.to_sym` so
all callers that compare against symbol literals (including the gem's
own create?/update?/destroy? predicates) continue to work unchanged.
Verified:
bundle exec ruby -Icore/test \
core/test/lib/workarea/configuration/administrable/fieldset_test.rb
→ 4 runs, 31 assertions, 0 failures, 0 errors — no BSON symbol warning
Also confirmed audit_log_entry_test and audit_log_middleware_test pass
with 0 failures.
This was referenced Feb 20, 2026
Author
Dispatcher Build Gate Summary (local)
Observation: core test output no longer prints the BSON Symbol deprecation warning on this branch (expected). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Resolves #627.
mongoid-audit_log(v0.6.1) declaresfield :action, :type => Symbolin itsEntrymodel. Mongoid 7.4.x emits a one-time warning —The BSON symbol type is deprecated; use String instead— whenever a field is registered with the RubySymboltype. This warning appears on every test boot, polluting CI/CD output and making it harder to spot real issues.Root cause: BSON 5.x deprecated the BSON Symbol wire type (0x0E). The warning is Mongoid's notice that using it will break in a future BSON version.
Fix — two parts:
core/lib/workarea/ext/freedom_patches/mongoid_audit_log.rb(new)Pre-sets Mongoid's one-time-warned flag before
require 'mongoid/audit_log'so the gem's own field definition cannot trigger the warning. The inline comment explains why this suppression is safe and correctly scoped.core/lib/workarea/ext/mongoid/audit_log_entry.rb(modified)In our existing
decorate Entryblock, re-declaresactionastype: String, overwrite: true— the actual underlying fix. A custom#actionreader wrapssuper&.to_symso the attribute still returns a Symbol, preserving the public contract (the gem's owncreate?/update?/destroy?predicates compare against symbol literals and continue to work unchanged).Test command output
Before this PR:
After this PR:
No BSON symbol warning. ✓
Also verified (no regressions):
core/test/lib/workarea/ext/mongoid/audit_log_entry_test.rb→ 3 runs, 9 assertions, 0 failurescore/test/middleware/workarea/audit_log_middleware_test.rb→ 1 run, 2 assertions, 0 failuresClient impact
None expected for most implementations.
The
actionattribute onMongoid::AuditLog::Entrystill returns a RubySymbol(e.g.:create), so any code comparing or switching on that value is unaffected.Data migration note: Not required for correctness. Existing documents with the deprecated BSON Symbol type (0x0E) are read back transparently — the BSON driver decodes them as Ruby
Symbol; Mongoid'sStringdemongoizer converts toString; the#actionreader calls.to_sym. New documents will store"create"(UTF-8 String, BSON type 0x02) going forward. A background migration to normalise old documents can be applied separately if desired; it is not a prerequisite for upgrading.