sources/ldap: fix API error when source has not synced yet

This commit is contained in:
Jens Langhammer 2021-02-27 16:29:36 +01:00
parent d2a35eb8de
commit a2e69bd250

View file

@ -1,5 +1,6 @@
"""Source API Views"""
from datetime import datetime
from time import time
from django.core.cache import cache
from django.db.models.base import Model
@ -68,7 +69,7 @@ class LDAPSourceViewSet(ModelViewSet):
def sync_status(self, request: Request, slug: str) -> Response:
"""Get source's sync status"""
source = self.get_object()
last_sync = cache.get(source.state_cache_prefix("last_sync"), None)
last_sync = cache.get(source.state_cache_prefix("last_sync"), time())
return Response(
LDAPSourceSyncStatusSerializer(
{"last_sync": datetime.fromtimestamp(last_sync)}