Avoid conflicts creating push configs
When a source pushes multiple datums for the first time after 2.15,
there can be a conflict creating a 'source.v2_push' source config.
Use the more atomic get_or_create to avoid that.
@@ -112,12 +112,13 @@ class SourceConfigManager(NaturalKeyManager):
'long_title': user.username,
}
)
- config = SourceConfig(
+ config, _ = SourceConfig.objects.get_or_create(
label=config_label,
- source=source,
- transformer=Transformer.objects.get(key=transformer_key),
+ defaults={
+ 'source': source,
+ 'transformer': Transformer.objects.get(key=transformer_key),
+ }
)
- config.save()
return config
