Skip to content

Timezone timestamp decoder behavior mismatch with hash vs. keyword arguments on v1.5.0 #524

@bravehager

Description

@bravehager

Description

The behavior of timestamp convenience classes such as PG::TextDecoder::TimestampUtc is different when using a hash vs. keyword arguments.

With a hash argument, we use Hash#merge, ensuring that flags are always set correctly even if they are passed via the constructor. With keyword arguments, it's possible to accidentally overwrite the value of flags such that they are not set correctly (see rails/rails#48055).

# Before
class TimestampUtc < Timestamp
  def initialize(params={})
    super(params.merge(flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_UTC))
  end
end

# After
class TimestampUtc < Timestamp
  def initialize(**kwargs)
    super(flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_UTC, **kwargs)
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions