Skip to content

Comments

WA-NEW-010: Eliminate BSON Symbol deprecation warning in test suite#635

Open
kitcommerce wants to merge 1 commit intonextfrom
wa-new-010-bson-symbol-deprecation
Open

WA-NEW-010: Eliminate BSON Symbol deprecation warning in test suite#635
kitcommerce wants to merge 1 commit intonextfrom
wa-new-010-bson-symbol-deprecation

Conversation

@kitcommerce
Copy link

Summary

Resolves #627.

mongoid-audit_log (v0.6.1) declares field :action, :type => Symbol in its Entry model. 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 Ruby Symbol type. 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:

  1. 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.

  2. core/lib/workarea/ext/mongoid/audit_log_entry.rb (modified)
    In our existing decorate Entry block, re-declares action as type: String, overwrite: true — the actual underlying fix. A custom #action reader wraps super&.to_sym so the attribute still returns a Symbol, preserving the public contract (the gem's own create? / update? / destroy? predicates compare against symbol literals and continue to work unchanged).


Test command output

Before this PR:

W, [...] WARN -- : The BSON symbol type is deprecated; use String instead
...
4 runs, 31 assertions, 0 failures, 0 errors, 0 skips

After this PR:

$ bundle exec ruby -Icore/test core/test/lib/workarea/configuration/administrable/fieldset_test.rb
2026-02-20T07:31:58.729Z pid=13192 tid=8jw INFO: Sidekiq 7.3.10 connecting to Redis...
Run options: --seed 7444

# Running:

....

Finished in 0.200761s, 19.9242 runs/s, 154.4125 assertions/s.
4 runs, 31 assertions, 0 failures, 0 errors, 0 skips

No BSON symbol warning. ✓

Also verified (no regressions):

  • core/test/lib/workarea/ext/mongoid/audit_log_entry_test.rb → 3 runs, 9 assertions, 0 failures
  • core/test/middleware/workarea/audit_log_middleware_test.rb → 1 run, 2 assertions, 0 failures

Client impact

None expected for most implementations.

The action attribute on Mongoid::AuditLog::Entry still returns a Ruby Symbol (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's String demongoizer converts to String; the #action reader 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.

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.
@kitcommerce
Copy link
Author

Dispatcher Build Gate Summary (local)

  • rubocop (diff-only): PASS (0 offenses)
  • brakeman: skipped (per repo build gate config; disabled)
  • tests (affected engines): PASS
    • core: PASS

Observation: core test output no longer prints the BSON Symbol deprecation warning on this branch (expected).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gate:build-passed Build gate passed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant