Explorar o código

fixed setting of the label in the result creation

Dimitri Korsch %!s(int64=4) %!d(string=hai) anos
pai
achega
0066240ed1
Modificáronse 1 ficheiros con 4 adicións e 6 borrados
  1. 4 6
      pycs/database/File.py

+ 4 - 6
pycs/database/File.py

@@ -145,13 +145,11 @@ class File(NamedBaseModel):
                             data=data)
 
         if label is not None:
-            if isinstance(label, int):
-                label = Label.query.get(label)
+            assert isinstance(label, (int, Label)), f"Wrong label type: {type(label)}"
+            if isinstance(label, Label):
+                label = label.id
 
-            elif not isinstance(label, Label):
-                raise ValueError(f"wrong label type: {type(label)}")
-
-            result.label = label
+            result.label_id = label
 
         self.commit()
         return result