BHTOM-Team / bhtom2

7 stars 2 forks source link

Aliases/names duplication should be possible #75

Closed wyrzykow closed 1 year ago

wyrzykow commented 1 year ago
ERROR:  duplicate key value violates unique constraint "bhtom_targets_targetname_name_key"
DETAIL:  Key (name)=(Gaia19dir) already exists.
STATEMENT:  INSERT INTO "bhtom_targets_targetname" ("target_id", "source_name", "name", "created", "modified") VALUES (346, 'GAIA_ALERTS', 'Gaia19dir', '2023-06-21T05:20:12.522507+00:00'::timestamptz, '2023-06-21T05:20:12.522520+00:00'::timestamptz) RETURNING "bhtom_targets_targetname"."id"

The aliases can have the same name, and the key should be the source, not the name, for example GAIA_ALERTS should be the key, not Gaia19dir.

wyrzykow commented 1 year ago

the problem is generated here:
TargetName.objects.create(target=target, source_name=k.name, name=v) in hooks.py

wyrzykow commented 1 year ago

or in update:

image

If you set GAIA_Alerts name to Gaia19dir and CPCS name to Gaia19dir.

wyrzykow commented 1 year ago

Fixed by modifying model for TargetName in bhtom_base,
name = models.CharField(max_length=100, unique=False, verbose_name='Alias') and making migrations (makemigrations, migrate).