diffsync icon indicating copy to clipboard operation
diffsync copied to clipboard

Empty DiffSync instance evaluates as false

Open smk4664 opened this issue 3 years ago • 1 comments
trafficstars

Environment

  • DiffSync version: 1.3.0
  • Python version: 3.6

Observed Behavior

When using diffsync within Nautobot-plugin-ssot, it would be nice to allow the Destination (Target) to have no data.

An empty DiffSync() evaluates to False. This causes a failure to proceed to the Diff.

the base DiffSync class has a len() method, an object’s default bool() casting must use that to determine whether it evaluates as truthy:

diffsync = DiffSync() bool(diffsync) False diffsync.add(DiffSyncModel()) bool(diffsync) True

Expected Behavior

diffsync proceeds to diff and then syncs data to the Destination (Target).

smk4664 avatar Dec 16 '21 17:12 smk4664

Workaround is to check explicitly is not None - see https://github.com/nautobot/nautobot-plugin-ssot/pull/18

glennmatthews avatar Dec 16 '21 17:12 glennmatthews

Having thought about this a little before I merge my fix PR into next-2.0 - I actually consider this the more intuitive behavior as opposed to always returning True. I think the workaround specified in the comment above to me is very acceptable. Opinions on closing without a change?

Kircheneer avatar Aug 18 '23 17:08 Kircheneer

See above comment.

Kircheneer avatar Feb 15 '24 07:02 Kircheneer