Skip to content

Commit

Permalink
[#418] Better exception handling for finding user in the db
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal-Kolomanski committed Jan 11, 2023
1 parent dcc8bd6 commit 87de420
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] - YYYY-MM-DD
### Added
- /health endpoint [@wujuu]
- pid for services [@wujuu]
### Changed
- **BREAKING CHANGE**: Adjust user actions handling to the new user action schema [@JanKapala]
### Fixed
- engine_version in the recommendations response [@Michal-Kolomanski]
- better exception handling for finding user in the DB [@Michal-Kolomanski]
### Removed

## [4.0.0] - 2022-10-26
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ To specify from which engine the recommendations are requested, provide an `engi
It is possible to define which algorithm should be used by default in the absence of the `engine_version` parameter by modifying the `DEFAULT_RECOMMENDATION_ALG` parameter from .env file
(look into [ENV variables](#env-variables) section).

### Engines
List of available engines (after training):
- `NCF` - returns `K` recommendations from the given context.
- `RL` - returns `K` recommendations from the given context.
- `Random` - returns `K` random recommendations from the given context.
- `NCFRanking` - used for sort by relevance.

### Seeding database
Note: Only available in development and testing environment.

Expand Down
11 changes: 6 additions & 5 deletions recommender/engines/base/base_inference_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ def _get_user(context: Dict[str, Any]) -> User:
"""

user_id, aai_uid = context.get("user_id"), context.get("aai_uid")

if not (user_id or aai_uid):
raise UserCannotBeIdentified()

return (
user = (
User.objects(id=user_id).first()
if user_id
else User.objects(aai_uid=aai_uid).first()
)

if user is None:
raise UserCannotBeIdentified()

return user

@abstractmethod
def _generate_recommendations(
self, user: User, candidates: Tuple[int], search_data: SearchData
Expand Down

0 comments on commit 87de420

Please sign in to comment.