@@ -175,7 +175,7 @@ def __init__(
175
175
version ,
176
176
zfile ,
177
177
zfile_hashvals ,
178
- computed_set_name ,
178
+ computed_set_id ,
179
179
):
180
180
self .user_id = user_id
181
181
self .sdf_filename = sdf_filename
@@ -185,7 +185,7 @@ def __init__(
185
185
self .version = version
186
186
self .zfile = zfile
187
187
self .zfile_hashvals = zfile_hashvals
188
- self .computed_set_name = computed_set_name
188
+ self .computed_set_id = computed_set_id
189
189
190
190
# using the same mechanism to pass messages as validation
191
191
self .messages : dict [str , Any ] = {
@@ -766,12 +766,13 @@ def task(self) -> tuple[ComputedSet, dict]:
766
766
767
767
# Do we have any existing ComputedSets?
768
768
try :
769
- computed_set = ComputedSet .objects .get (name = self .computed_set_name )
769
+ computed_set = ComputedSet .objects .get (pk = self .computed_set_id )
770
770
# refresh some attributes
771
771
computed_set .md_ordinal = F ("md_ordinal" ) + 1
772
772
computed_set .upload_date = datetime .date .today ()
773
773
computed_set .save ()
774
- except ComputedSet .DoesNotExist :
774
+ except (ValueError , ComputedSet .DoesNotExist ):
775
+ # ValueError when pk is None
775
776
# no, create new
776
777
777
778
today : datetime .date = datetime .date .today ()
@@ -790,16 +791,30 @@ def task(self) -> tuple[ComputedSet, dict]:
790
791
f"{ truncated_submitter_method } -{ str (today )} -"
791
792
+ f"{ get_column_letter (new_ordinal )} "
792
793
)
793
- logger .info ('Creating new ComputedSet "%s"' , cs_name )
794
-
795
- computed_set = ComputedSet (
796
- name = cs_name ,
797
- md_ordinal = new_ordinal ,
798
- upload_date = today ,
799
- method = self .submitter_method [: ComputedSet .LENGTH_METHOD ],
800
- target = target ,
801
- spec_version = float (self .version .strip ("ver_" )),
802
- )
794
+
795
+ # now that I have a name, I can check whether this
796
+ # target already has this set
797
+ try :
798
+ # this feels wrong, I think it's better if the
799
+ # object is resolved in the view.. or maybe in
800
+ # validate task..
801
+ computed_set = ComputedSet .objects .get (
802
+ name = cs_name ,
803
+ target = target ,
804
+ )
805
+ except ComputedSet .DoesNotExist :
806
+ # and only now create new set
807
+ logger .info ('Creating new ComputedSet "%s"' , cs_name )
808
+
809
+ computed_set = ComputedSet (
810
+ name = cs_name ,
811
+ md_ordinal = new_ordinal ,
812
+ upload_date = today ,
813
+ method = self .submitter_method [: ComputedSet .LENGTH_METHOD ],
814
+ target = target ,
815
+ spec_version = float (self .version .strip ('ver_' )),
816
+ )
817
+
803
818
if self .user_id :
804
819
try :
805
820
computed_set .owner_user = User .objects .get (id = self .user_id )
0 commit comments