Skip to content

Commit

Permalink
Flake8 fixes and formatting adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Ngai committed Jul 18, 2024
1 parent 4ec4952 commit 1865701
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 3 additions & 2 deletions woudc_data_registry/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
WDR_DB_NAME = os.getenv('WDR_DB_NAME')
WDR_SEARCH_TYPE = os.getenv('WDR_SEARCH_TYPE', 'elasticsearch')
WDR_SEARCH_URL = os.getenv('WDR_SEARCH_URL')
WDR_SEARCH_INDEX_BASENAME=os.getenv('WDR_SEARCH_INDEX_BASENAME')
WDR_SEARCH_INDEX_BASENAME = os.getenv('WDR_SEARCH_INDEX_BASENAME')
WDR_WAF_BASEDIR = os.getenv('WDR_WAF_BASEDIR')
WDR_WAF_BASEURL = os.getenv('WDR_WAF_BASEURL', 'https://woudc.org/archive')
WDR_ERROR_CONFIG = os.getenv('WDR_ERROR_CONFIG')
Expand All @@ -73,7 +73,8 @@
WDR_UV_INDEX_FORMULA_LOOKUP = os.getenv('WDR_UV_INDEX_FORMULA_LOOKUP')

if not WDR_SEARCH_INDEX_BASENAME:
msg = 'WDR_SEARCH_INDEX_BASENAME was not set. Defaulting to: woudc_data_registry'
msg = 'WDR_SEARCH_INDEX_BASENAME was not set. \
Defaulting to: woudc_data_registry'
LOGGER.warning(msg)
WDR_SEARCH_INDEX_BASENAME = 'woudc_data_registry'

Expand Down
9 changes: 6 additions & 3 deletions woudc_data_registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def query_distinct_by_fields(
conditions = []
target_fields = values.keys()

LOGGER.debug(f'Querying distinct values by fields {target_fields} for {domain}')
LOGGER.debug(f'Querying distinct values \
by fields {target_fields} for {domain}')

for field in target_fields:
table_field = getattr(obj, field)
Expand Down Expand Up @@ -332,9 +333,11 @@ def save(self, obj=None):
try:
flag_name = '_'.join([obj.__tablename__, 'enabled'])
if registry_config.get(flag_name, True):
self.session.add(obj) # Use merge if needed: self.session.merge(obj)
# Use merge if needed: self.session.merge(obj)
self.session.add(obj)
else:
LOGGER.info(f'Registry persistence for model {obj.__tablename__} disabled, skipping')
LOGGER.info(f'Registry persistence for \
model {obj.__tablename__} disabled, skipping')
return

LOGGER.debug(f'Committing save of {obj}')
Expand Down
15 changes: 11 additions & 4 deletions woudc_data_registry/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,11 @@ def index(self, domain, target):
}

LOGGER.debug(f'Indexing 1 document into {index_name}')
self.connection.update(index=index_name, id=target['id'],
body=wrapper)
self.connection.update(
index=index_name,
id=target['id'],
body=wrapper
)
else:
# Index/update multiple documents using bulk API.
wrapper = ({
Expand All @@ -1199,8 +1202,12 @@ def index(self, domain, target):
} for document in target)

LOGGER.debug(f'Indexing documents into {index_name}')
helpers.bulk(self.connection, wrapper,
raise_on_error=False, raise_on_exception=False)
helpers.bulk(
self.connection,
wrapper,
raise_on_error=False,
raise_on_exception=False
)

return True

Expand Down

0 comments on commit 1865701

Please sign in to comment.