'target_type' parameter for Events API is nil for projects
Summary
When events API is used with target_type
parameter for projects, it just returns []
. Other target types lists the events.
After further investigation, we realized that target_type
is nil for projects.
irb(main):008:0> pp Event.where(project_id: 8)
[#<Event:0x00007fcc17f42938
project_id: 8,
author_id: 1,
target_id: nil,
created_at: Fri, 21 Apr 2023 04:58:08.340281000 UTC +00:00,
updated_at: Fri, 21 Apr 2023 04:58:08.340281000 UTC +00:00,
action: "created",
target_type: nil,
group_id: nil,
fingerprint: nil,
id: 35>,
#<PushEvent:0x00007fcc17f427f8
project_id: 8,
author_id: 1,
target_id: nil,
created_at: Fri, 21 Apr 2023 04:58:09.697271000 UTC +00:00,
updated_at: Fri, 21 Apr 2023 04:58:09.697271000 UTC +00:00,
action: "pushed",
target_type: nil,
group_id: nil,
fingerprint: nil,
id: 36>]
Issues, merge_requests, milestones, notes, wiki_page_metadata, and epics use create_record_event
method, so they get a target_type
recorded.
$ git grep "create_record_event"
app/services/event_create_service.rb: create_record_event(issue, current_user, :created)
app/services/event_create_service.rb: create_record_event(issue, current_user, :closed)
app/services/event_create_service.rb: create_record_event(issue, current_user, :reopened)
app/services/event_create_service.rb: create_record_event(merge_request, current_user, :created).tap do
app/services/event_create_service.rb: create_record_event(merge_request, current_user, :closed).tap do
app/services/event_create_service.rb: create_record_event(merge_request, current_user, :reopened)
app/services/event_create_service.rb: create_record_event(merge_request, current_user, :merged).tap do
app/services/event_create_service.rb: create_record_event(milestone, current_user, :created)
app/services/event_create_service.rb: create_record_event(milestone, current_user, :closed)
app/services/event_create_service.rb: create_record_event(milestone, current_user, :reopened)
app/services/event_create_service.rb: create_record_event(milestone, current_user, :destroyed)
app/services/event_create_service.rb: create_record_event(note, current_user, :commented).tap do
app/services/event_create_service.rb: create_record_events(records, current_user)
app/services/event_create_service.rb: create_record_events(designs.zip([:destroyed].cycle), current_user)
app/services/event_create_service.rb: create_record_event(wiki_page_meta, author, action, fingerprint.presence)
app/services/event_create_service.rb: create_record_event(merge_request, current_user, :approved)
app/services/event_create_service.rb: def create_record_event(record, current_user, status, fingerprint = nil)
app/services/event_create_service.rb: def create_record_events(tuples, current_user)
ee/app/services/ee/event_create_service.rb: create_record_event(epic, current_user, :created)
ee/app/services/ee/event_create_service.rb: create_record_event(epic, current_user, :closed)
ee/app/services/ee/event_create_service.rb: create_record_event(epic, current_user, :reopened)
project
uses create_event
app/services/event_create_service.rb: create_event(project, current_user, :joined)
app/services/event_create_service.rb: create_event(project, current_user, :left)
app/services/event_create_service.rb: create_event(project, current_user, :expired)
app/services/event_create_service.rb: create_event(project, current_user, :created)
app/services/event_create_service.rb: create_event(record.resource_parent, current_user, status,
app/services/event_create_service.rb: new_event = create_event(project, current_user, :pushed)
app/services/event_create_service.rb: def create_event(resource_parent, current_user, status, attributes = {})
Steps to reproduce
Example requests:
https://gitlab.com/api/v4/users/:id/events?target_type=project
https://gitlab.com/api/v4/events?target_type=project
Response is []
Example Project
What is the current bug behavior?
Events should be listed for project target type with the events API.
What is the expected correct behavior?
Events API doesn't return the results for project target type.
Relevant logs and/or screenshots
irb(main):004:0> events = EventCollection.new(current_user.authorized_projects).all_project_events
=> #<ActiveRecord::Relation [#<Event project_id: 22, author_id: 6, target_id: 4, created_at: "2023-04-20 02:57:24.958850000 +0000", updated_at: "2023-04-20 02:57:24.958850000 +0000", action: "created", target_type: "Issue", group_id: nil...
irb(main):005:0> project_target_events = events.where(target_type: Event::TARGET_TYPES["project"].name)
=> #<ActiveRecord::Relation []>
irb(main):006:0> issue_target_events = events.where(target_type: Event::TARGET_TYPES["issue"].name)
=> #<ActiveRecord::Relation [#<Event project_id: 22, author_id: 6, target_id: 4, created_at: "2023-04-20 02:57:24.958850000 +0000", updated_at: "2023-04-20 02:57:24.958850000 +0000", action: "created", target_type: "Issue", group_id: nil...
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
project
can use create_record_event
method as well.