Merge pull request #8776 from colinux/fix-deadlocks

Fix: corrige peut-être des deadlocks postgresql sur le champ SIRET
This commit is contained in:
Colin Darie 2023-03-21 11:11:46 +00:00 committed by GitHub
commit 3a9b2d99e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 9 deletions

View file

@ -9,12 +9,11 @@ module SiretChampEtablissementFetchableConcern
return clear_etablissement!(:invalid_checksum) if invalid_because?(siret, :checksum) # i18n-tasks-use t('errors.messages.invalid_siret_checksum')
return clear_etablissement!(:not_found) unless (etablissement = APIEntrepriseService.create_etablissement(self, siret, user&.id)) # i18n-tasks-use t('errors.messages.siret_not_found')
update!(value: siret, etablissement: etablissement)
update!(etablissement: etablissement)
rescue => error
if error.try(:network_error?) && !APIEntrepriseService.api_up?
# TODO: notify ops
update!(
value: siret,
etablissement: APIEntrepriseService.create_etablissement_as_degraded_mode(self, siret, user.id)
)
@etablissement_fetch_error_key = :api_entreprise_down

View file

@ -15,8 +15,10 @@
- when :api_entreprise_down
= t('errors.messages.api_entreprise_down')
- when :empty
// NOOP
- else
- if siret.present?
- if siret.present? # NOTE: probably always true because siret is a symbol or the string value
- if siret == etablissement&.siret && raison_sociale_or_name(etablissement).present?
= render EditableChamp::EtablissementTitreComponent.new(etablissement: etablissement)
- else

View file

@ -109,7 +109,6 @@ describe Champs::SiretController, type: :controller do
it 'saves the etablissement in degraded mode and SIRET on the model' do
champ.reload
expect(champ.value).to eq(siret)
expect(champ.etablissement.siret).to eq(siret)
expect(champ.etablissement.as_degraded_mode?).to be true
end
@ -143,7 +142,6 @@ describe Champs::SiretController, type: :controller do
it 'populates the etablissement and SIRET on the model' do
champ.reload
expect(champ.value).to eq(siret)
expect(champ.etablissement.siret).to eq(siret)
expect(champ.etablissement.naf).to eq("6202A")
expect(dossier.reload.etablissement).to eq(nil)

View file

@ -68,8 +68,6 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
before { expect(APIEntrepriseService).to receive(:api_up?).and_return(false) }
it { expect { fetch_etablissement! }.to change { champ.reload.value }.to(siret) }
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement } }
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.as_degraded_mode? }.to(true) }
@ -96,8 +94,6 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
let(:api_etablissement_status) { 200 }
let(:api_etablissement_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
it { expect { fetch_etablissement! }.to change { champ.reload.value }.to(siret) }
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.siret }.to(siret) }
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.naf }.to("6202A") }