-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
I have the following code:
class ApiKey(models.Model):
tenant = models.ForeignKey(Tenant, null=False, on_delete=models.CASCADE)
key = secured_fields.EncryptedCharField(
max_length=constants.CHARFIELD_SIZE_128, unique=True, editable=False, searchable=True
)
def save(self, *args, **kwargs):
if not self.key:
self.key = secrets.token_urlsafe(64)
super().save(*args, **kwargs)And the following code:
api_key = request.headers.get("x-api-key")
print("api_key", api_key)
print(ApiKey.objects.first().key == api_key) # This returns True
provider_api_key = ApiKey.objects.get(key=api_key) # This fails, most of the time, with self.model.DoesNotExist. But, sometimes it works!!Am I doing something wrong? I set the field to searchable. I was thinking with that would be enough to filter and get by it. But, it's not working for me. Why does it works sometimes?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels