'The instance_guid is the best way to uniquely identify an LTI consumer.
However according to the LTI spec, the instance_guid field is optional
and so cannot be relied upon to be present.
This method first attempts to find an LtiConsumer by instance_guid.
Failing that, it tries to find a record with a matching consumer_key.
This can be the case if the LtiConsumer record was created as the result
of an LTI launch with no instance_guid.
If the instance_guid is now present, the LtiConsumer model will be
supplemented with the instance_guid, to more concretely identify the
consumer.
In practice, nearly all major LTI consumers provide an instance_guid, so
the fallback mechanism of matching by consumer key should be rarely
required.'

@staticmethod
def get_or_supplement(instance_guid, consumer_key):

    consumer = None
    if instance_guid:
        try:
            consumer = LtiConsumer.objects.get(instance_guid=instance_guid)
        except LtiConsumer.DoesNotExist:
            pass
    if (not consumer):
        consumer = LtiConsumer.objects.get(consumer_key=consumer_key)
    if (instance_guid and (not consumer.instance_guid)):
        consumer.instance_guid = instance_guid
        consumer.save()
    return consumer
