Skip to content

Return an instance of Feedback from Occurrence#_feedback methods

What does this MR do?

Currently Occurrence#(dismissal|issue|merge_request)_feedback methods are returning an instance of BatchLoader which mimics almost all the behaviour of proxied object but it's not perfect.

We can't use safe navigation operator on these return objects because they are not actually nil since the Ruby VM just checks the object to see if it's NIL_P before sending the message. This causes getting NoMethodError on nil:NilClass which causes tears on developers' eye.

Here we are explicitly trying to return an instance of Vulnerabilities::Feedback model.

Also before there was a hidden N+1 query issue with the previous implementation. Because in the previous implementation we were trying to load all the feedback records for an occurrence and then marking the ones returned by the query as loaded which was causing another database query to happen for the feedback which wasn't returned by the previous query.

You can test this behaviour on master like so;

occurrence = Vulnerabilities::Occurrence.first # Find an occurrence with **only** dismissal feedback.
occurrence.dismissal_feedback # => returns the feedback and the assumption was it also loads other types of feedback
occurrence.issue_feedback # => Fires a new database query!

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Mehmet Emin INAC

Merge request reports