Skip to content

Commit

Permalink
add case for UUIDs and fix queryset bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DevDaveFrame committed Nov 30, 2023
1 parent 1df2737 commit 80eda60
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bigquery_exporter/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import logging
from uuid import UUID
from google.cloud import bigquery
from google.oauth2 import service_account
from google.api_core.exceptions import GoogleAPICallError
Expand Down Expand Up @@ -105,7 +106,7 @@ def export(self, pull_date=None, *args, **kwargs):
if reporting_data:
self._push_to_bigquery(reporting_data)
logger.info(
f'Finished exporting {len(self.queryset)} {self.model} in {datetime.datetime.now() - pull_time}'
f'Finished exporting {len(queryset)} {self.model} in {datetime.datetime.now() - pull_time}'
)
except Exception as e:
logger.error(f'Error while exporting {self.model}: {e}')
Expand Down Expand Up @@ -134,6 +135,8 @@ def _process_queryset(self, queryset, pull_time):
# if the model is a datetime, sanitize to a BQ compliant string
if isinstance(model_field, datetime.datetime):
processed_dict[field] = model_field.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(model_field, UUID):
processed_dict[field] = str(model_field)
else:
processed_dict[field] = model_field
processed_queryset.append(processed_dict)
Expand Down

0 comments on commit 80eda60

Please sign in to comment.