Resolve "Error 500 for /api/v4/projects/ID/services/jira"
What does this MR do?
This MR fixes a NoMethodError (undefined method slice for nil:NilClass)
that occurs at /api/v4/projects/:id/services/:service
when :service
is an issue tracker service and has not yet been enabled for the project.
In this particular case, the IssueTrackerService
is instantiated but is not persisted to the database. The check for service.data_fields_present?
in lib/api/entities.rb
returns false and this results in service.properties.slice
being called, which results in the NoMethodError
.
The proposed solution is to only check data_fields.present?
if the service is not persisted. My other thought was to simply change data_fields.persisted?
to data_fields.present?
, but that resulted in failing tests in spec/requests/api/services_spec.rb
. I think we could update the tests there if we wanted to only check data_fields.present?
in data_fields_present?
Screenshots
http://localhost:3000/api/v4/projects/7/services/jira)
Before (http://localhost:3000/api/v4/projects/7/services/jira)
After (Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation created/updated or follow-up review issue created -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers
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
Closes #34770 (closed)