Commit 2d1ceca0 authored by Stan Hu's avatar Stan Hu

Don't error out in system hook if user has `nil` datetime columns

Deleting a user would fail in the system hooks if the user had
`nil` column in `datetime` or `updated_at` fields.

Closes #43871
parent 8a0052c0
...@@ -20,8 +20,8 @@ class SystemHooksService ...@@ -20,8 +20,8 @@ class SystemHooksService
def build_event_data(model, event) def build_event_data(model, event)
data = { data = {
event_name: build_event_name(model, event), event_name: build_event_name(model, event),
created_at: model.created_at.xmlschema, created_at: model.created_at&.xmlschema,
updated_at: model.updated_at.xmlschema updated_at: model.updated_at&.xmlschema
} }
case model case model
......
---
title: Don't error out in system hook if user has `nil` datetime columns
merge_request:
author:
type: fixed
...@@ -70,6 +70,14 @@ describe SystemHooksService do ...@@ -70,6 +70,14 @@ describe SystemHooksService do
expect(data[:project_visibility]).to eq('private') expect(data[:project_visibility]).to eq('private')
end end
it 'handles nil datetime columns' do
user.update_attributes(created_at: nil, updated_at: nil)
data = event_data(user, :destroy)
expect(data[:created_at]).to be(nil)
expect(data[:updated_at]).to be(nil)
end
context 'group_rename' do context 'group_rename' do
it 'contains old and new path' do it 'contains old and new path' do
allow(group).to receive(:path_was).and_return('old-path') allow(group).to receive(:path_was).and_return('old-path')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment