Skip to content

Commit

Permalink
Maintain compatibility with earlier nil-values fix from main (#1136)
Browse files Browse the repository at this point in the history
An earlier commit on main (#d5422b46 in PR #1136) fixed a subtle
issue when overriding default values with nil, by explicitly setting
`.created_at` and other attributes from the existing item when it was
being replaced. This caused issues on this PostgreSQL branch after
rebasing, as ActiveRecord behaves more as expected with respect to
`created_at` and therefore the line creating a local `created_at`
variable had been removed.

This commit reintroduces that variable, and tests now pass again.
  • Loading branch information
aldavidson authored and brucebolt committed Dec 27, 2023
1 parent 29b36f0 commit 9a8a058
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/content_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def self.create_or_replace(base_path, attributes, log_entry)

result = previous_item ? :replaced : :created

# This doesn't seem to get set correctly on an upsert so this is to
# maintain it
created_at = previous_item ? previous_item.created_at : Time.zone.now.utc

# This awkward construction is necessary to maintain the required behaviour -
# a content item sent to Content Store is a complete entity (as defined in a schema)
# and no-remnants of the item it replaces should remain.
Expand Down

0 comments on commit 9a8a058

Please sign in to comment.