Deployment#older_than_last_successful_deployment? raises "NoMethodError: undefined method `<' for nil:NilClass"
Summary
Extracted from this issue on Sentry.
Deployment#older_than_last_successful_deployment?
sometimes raises
NoMethodError: undefined method `<' for nil:NilClass
Update: Using this more recent copy of the error
in the comparison
self.id < last_deployment_id
Somehow, the method gets called for a deployment without an id
Steps to reproduce
See the new test in !144538 (merged)
Example Project
What is the current bug behavior?
The job blows up and throws the NoMethodError
What is the expected correct behavior?
Nothing, we shouldn't be executing this check for unsaved deployment objects. The error messages should go away and be replaced by a serene silence.
Relevant logs and/or screenshots
Example stacktrace (truncated to only relevant lines):
NoMethodError: undefined method `<' for nil:NilClass
from app/models/deployment.rb:310:in `older_than_last_successful_deployment?'
from app/models/concerns/ci/deployable.rb:47:in `outdated_deployment?'
from gems/gitlab-utils/lib/gitlab/utils/strong_memoize.rb:138:in `bind_call'
from gems/gitlab-utils/lib/gitlab/utils/strong_memoize.rb:138:in `block (2 levels) in do_strong_memoize'
from gems/gitlab-utils/lib/gitlab/utils/strong_memoize.rb:34:in `strong_memoize'
from gems/gitlab-utils/lib/gitlab/utils/strong_memoize.rb:137:in `block in do_strong_memoize'
from app/services/ci/process_build_service.rb:30:in `enqueue'
from ee/app/services/ee/ci/process_build_service.rb:26:in `enqueue'
from app/services/ci/process_build_service.rb:25:in `process'
from ee/app/services/ee/ci/process_build_service.rb:17:in `process'
from app/services/ci/process_build_service.rb:7:in `execute'
from app/services/ci/pipeline_processing/atomic_processing_service.rb:100:in `block in update_job!'
from lib/gitlab/optimistic_locking.rb:18:in `block in retry_lock'
from app/models/concerns/cross_database_modification.rb:92:in `block in transaction'
from activerecord (7.0.8) lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
Possible fixes
!144935 (merged) and !144538 (merged)
How to Validate in Production
Edited by drew stachon