The function:
@lru_cache()
def movie_repository(settings: Settings = Depends(settings_instance)):
"""
Movie repository instance to be used as a Fast API dependency.
"""
return MongoMovieRepository(
connection_string=settings.mongo_connection_string,
database=settings.mongo_database_name,
)
Will cause the following exception:
TypeError: unhashable type: 'Settings'
To fix the exception, please override hash function from Settings as so:
class Settings(BaseSettings):
[...]
def __hash__(self) -> int:
return 1
The course bypasses the exception by using a closure function but that doesn't work as expected.