Skip to content

Commit

Permalink
fix(executor): allowing missing with/drivers keywords (#1967)
Browse files Browse the repository at this point in the history
* fix(executor): allowing missing with/drivers keywords

* style(resources): adapt to new executor yaml syntax
  • Loading branch information
hanxiao committed Feb 17, 2021
1 parent 89cf0bc commit f2046fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
7 changes: 5 additions & 2 deletions jina/executors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def _get_drivers_from_requests(_requests):
drivers = drivers_spec
common_kwargs = {}
elif isinstance(drivers_spec, dict):
drivers = drivers_spec['drivers']
common_kwargs = drivers_spec['with']
drivers = drivers_spec.get('drivers', [])
common_kwargs = drivers_spec.get('with', {})
else:
raise TypeError(f'unsupported type of driver spec: {drivers_spec}')

Expand All @@ -193,6 +193,9 @@ def _get_drivers_from_requests(_requests):
_drivers[r].clear()
_drivers[r] = new_drivers

if not _drivers[r]:
_drivers.pop(r)

return _drivers

def _fill_metas(self, _metas):
Expand Down
5 changes: 2 additions & 3 deletions jina/types/document/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,12 @@ def get_attrs(self, *args) -> Dict[str, Any]:
else:
value = dunder_get(self._pb_body, k)

if not value:
if value is None:
raise ValueError

ret[k] = value
continue
except (AttributeError, ValueError):
default_logger.warning(f'Could not get attribute from key {k}, returning None')
default_logger.warning(f'Could not get attribute `{typename(self)}.{k}`, returning `None`')
ret[k] = None
return ret

Expand Down
2 changes: 1 addition & 1 deletion jina/types/sets/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _extract_docs(self, attr: str) -> Tuple['np.ndarray', 'DocumentSet']:

if bad_docs and docs_pts:
default_logger.warning(
f'found {len(bad_docs)} no-content docs at granularity {docs_pts[0].granularity}')
f'found {len(bad_docs)} no-{attr} docs at granularity {docs_pts[0].granularity}')

return contents, DocumentSet(docs_pts)

Expand Down
22 changes: 22 additions & 0 deletions tests/unit/executors/test_set_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ def test_fill_default_with_index_request():
print(be._drivers['IndexRequest'][0]._init_kwargs_dict)


y_fill_default_with_index_request_no_with = """
!BaseEncoder
requests:
use_default: true
on:
IndexRequest:
drivers:
- !FilterQL
with:
lookups:
mime_type: image/jpeg
- !EncodeDriver {}
"""


def test_with_common_kwargs_on_index_no_with():
be = BaseExecutor.load_config(y_fill_default_with_index_request_no_with)
assert len(be._drivers) == 6
assert isinstance(be._drivers['IndexRequest'][1], EncodeDriver)
assert isinstance(be._drivers['IndexRequest'][0], FilterQL)


y_fill_default_with_index_request_with_common = """
!BaseEncoder
requests:
Expand Down

0 comments on commit f2046fa

Please sign in to comment.