GitHub Import: Skip label link creation if issue not found
What does this MR do and why?
Corresponding issue: ActiveRecord::RecordInvalid: Validation failed:... (#389266 - closed)
There was a lot of occurrences of error in GitHub Import
ActiveRecord::RecordInvalid: Validation failed: Target can't be blank
from activerecord (6.1.6.1) lib/active_record/validations.rb:80:in `raise_validation_error'
from activemodel (6.1.6.1) lib/active_model/validations.rb:383:in `validate!'
from app/models/concerns/bulk_insert_safe.rb:171:in `block in _bulk_insert_item_attributes'
from app/models/concerns/bulk_insert_safe.rb:170:in `map'
from app/models/concerns/bulk_insert_safe.rb:170:in `_bulk_insert_item_attributes'
from app/models/concerns/bulk_insert_safe.rb:158:in `block (2 levels) in _bulk_insert_all!'
from app/models/concerns/bulk_insert_safe.rb:157:in `each'
from app/models/concerns/bulk_insert_safe.rb:157:in `each_slice'
from app/models/concerns/bulk_insert_safe.rb:157:in `each'
from app/models/concerns/bulk_insert_safe.rb:157:in `flat_map'
from app/models/concerns/bulk_insert_safe.rb:157:in `block in _bulk_insert_all!'
from app/models/concerns/bulk_insert_safe.rb:156:in `_bulk_insert_all!'
from app/models/concerns/bulk_insert_safe.rb:91:in `bulk_insert!'
from lib/gitlab/github_import/importer/label_links_importer.rb:43:in `create_labels'
from lib/gitlab/github_import/importer/label_links_importer.rb:20:in `execute'
from lib/gitlab/github_import/importer/issue_and_label_links_importer.rb:20:in `execute'
from app/workers/concerns/gitlab/github_import/object_importer.rb:38:in `import'
from app/workers/concerns/gitlab/github_import/rescheduling_methods.rb:29:in `try_import'
from app/workers/concerns/gitlab/github_import/rescheduling_methods.rb:18:in `perform'
The issue is hard to reproduce. I tried various imports and didn't hit this error unless manually mimic the behavior. The only possible scenarios that I can see is when the target is blank:
- The project has been deleted since scheduling issue import jobs. In this case, it silently skips issue creation which results in a blank target_id. https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/github_import/importer/issue_importer.rb#L68
- The issue failed to be created due to validation errors, which is also results on blank target_id
- The Redis cache was cleared (don't think it is happening)
Bearing that in mind it is logical to skip label_link creation if the issue failed to be created for any reason.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Kristina Doskich