def test_update_traits_deletes_when_nulled_out(environment: Environment) -> None:
    """
    This is quite a long test to verify the update traits functionality correctly
    handles updating and creating traits.
    """
    # Given
    # an identity
    identity = Identity.objects.create(identifier="identifier", environment=environment)

    # that already has 2 traits
    trait_1_key = "trait_1"
    trait_1_value = 1
    trait_2_key = "trait_2"
    trait_2_value = 2
    create_trait_for_identity(identity, trait_1_key, trait_1_value)
    create_trait_for_identity(identity, trait_2_key, trait_2_value)

    # and a list of trait data items that should delete 1 and leave the other
    trait_data_items = [
        generate_trait_data_item(trait_key=trait_1_key, trait_value=None)
    ]

    # When
    updated_traits = identity.update_traits(trait_data_items)

    # Then
    # 1 trait is returned
    assert len(updated_traits) == 1

    # and the nulled out trait has been deleted
    assert not Trait.objects.filter(trait_key=trait_1_key, identity=identity).exists()

    # and the returned trait is untouched
    assert updated_traits[0].trait_key == trait_2_key
    assert updated_traits[0].trait_value == trait_2_value

    This is quite a long test to verify the update traits functionality correctly
    handles updating and creating traits.
    
api/tests/unit/environments/identities/test_unit_identities_models.py