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
Description
The behavior of timestamp convenience classes such as
PG::TextDecoder::TimestampUtcis different when using a hash vs. keyword arguments.With a hash argument, we use
Hash#merge, ensuring thatflagsare always set correctly even if they are passed via the constructor. With keyword arguments, it's possible to accidentally overwrite the value offlagssuch that they are not set correctly (see rails/rails#48055).