Skip to content

Commit

Permalink
Check for Empty values with is operator (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjakob authored Jun 5, 2023
1 parent 5e3d335 commit 0084492
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions django_fakery/faker_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def build_one(

value = fields.get(field_name, Empty)
if isinstance(model_field, models.ForeignKey):
if value == Empty:
if value is Empty:
value = fields.get(field_name + "_id", Empty)

if value == rels.SELECT:
Expand All @@ -156,15 +156,15 @@ def build_one(

value = fks_cache.get(cache_key, Empty)

if value == Empty:
if value is Empty:
try:
value = qs[0]
except IndexError:
value = evaluator.fake_value(model, model_field)

fks_cache[cache_key] = value

if not make_fks and ((value == Empty) or (value and value.pk is None)):
if not make_fks and ((value is Empty) or (value and value.pk is None)):
raise ForeignKeyError(
"Field {} is a required ForeignKey, but the related {}.{} model"
" doesn't have the necessary primary key.".format(
Expand All @@ -176,7 +176,7 @@ def build_one(

field_name += "_id"

if value != Empty:
if value is not Empty:
value = evaluator.evaluate(value)
else:
if model_field.choices:
Expand Down

0 comments on commit 0084492

Please sign in to comment.