warnings.warn() in library code if the issue is avoidable and the client application should be modified to eliminate the warning
logging.warning() if there is nothing the client application can do about the situation, but the event should still be noted
Using warnings about n+1 query is more pythonic.
https://docs.python.org/3/howto/logging.html#when-to-use-logging
It is also convenient to use with pytest. Because pytest creates a report on all warnings. https://docs.pytest.org/en/7.1.x/how-to/capture-warnings.html
Sorry for my english.