Skip to content

Commit

Permalink
fix for censorship label bug (#454)
Browse files Browse the repository at this point in the history
* fix for censorship label bug

* fix: don't iterate on `None` from gen_metadata key

`dict.get(...)` returns the value of a key if it is set. The default parameter (the second parameter) only returns a default value **if the key does not exist**. Therefore, if the key `gen_metadata` is set in `kwargs`, and is set to `None`, then `kwargs.get("gen_metadata", [])` will return `None` and **not** an empty list (`[]`).

---------

Co-authored-by: tazlin <[email protected]>
  • Loading branch information
rbrtcs1 and tazlin authored Sep 27, 2024
1 parent a26fbd9 commit 73a88ab
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions horde/classes/stable/processing_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ def log_aborted_generation(self):

def set_generation(self, generation, things_per_sec, **kwargs):
state = kwargs.get("state", "ok")
for metadata in kwargs.get("gen_metadata", []):
if metadata.get('value') == 'csam':
state = 'csam'
gen_metadata = kwargs.get("gen_metadata") or []
for metadata in gen_metadata:
if metadata.get("type") != "censorship":
# this metadata isnt about censorship
continue
if metadata.get("value") == "csam":
state = "csam"
else:
state = 'censored'
state = "censored"
if state in ["censored", "csam"]:
self.censored = True
db.session.commit()
Expand Down

0 comments on commit 73a88ab

Please sign in to comment.