Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5433

Rails 7 deprecates Time#to_s(format) and replaces it with Time#to_fs(format)

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 8.0.3, 7.5.2
    • Affects Version/s: 8.0.1, 7.5.0, 7.4.1
    • Component/s: None
    • Labels:
      None
    • Fully Compatible

      Rails 7 deprecates the ActiveSupport supplied Time#to_s with a format argument that is used by Mongoid::Cacheable#cache_key to generate a cache key In a Rails 7 project using caching, a deprecation warning will appear in the server logs every time the cache_key method is called.

       

      The solution suggested by the deprecation warning is to switch to ActiveSupport's new Time#to_fs method. However, that method doesn't seem to exist in older versions of ActiveSupport, which would be potentially in use by users of mongoid using older versions of rails. Therefore, I think that using the (unfortunately verbose named) Time#to_formatted_s might be the best option. Older versions of rails have Time#to_formatted_s aliased in ActiveSupport to Time#to_s, whereas Time#to_fs is a new method. The new Time#to_fs method is also aliased to Time#to_formatted_s, so calling it that way should allow it to work without causing deprecation warnings in Rails 7 and earlier versions. It will also prevent any code breaking that could occur when ActiveSupport actually removes their Time#to_s code.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            dan@cacheventures.com Daniel Arnold
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: