After migrating a project to a different shard, creating a fork returns a 500

Discovered during the project migration of gitlab-foss from file08 to a new gitaly server file-cny01, once the migration completed forks were returning 500s.

We believe this error was introduced when deduplication was added.

NoMethodError: undefined method `persisted?' for false:FalseClass

https://sentry.gitlab.net/gitlab/gitlabcom/issues/1106473/

NoMethodError: undefined method `persisted?' for false:FalseClass
  application_record.rb:35:in `block in safe_find_or_create_by!'
    record.validate! unless record.persisted?
  application_record.rb:34:in `tap'
    safe_find_or_create_by(*args).tap do |record|
  application_record.rb:34:in `safe_find_or_create_by!'
    safe_find_or_create_by(*args).tap do |record|
  gitlab/metrics/instrumentation.rb:161:in `block in safe_find_or_create_by!'
    .measure { super }
  gitlab/metrics/method_call.rb:36:in `measure'
    retval = yield
...
(140 additional frame(s) were not displayed)

NoMethodError: undefined method `persisted?' for false:FalseClass
Edited by John Jarvis