Use ENGINE if specified
The current behaviour is to use the postgres backend bundled with django. However, for custom backends, like custom credentials fetching, or credentials reload at runtime, one needs to override both the DatabaseLayer and the PostgresChannelLayer. An example is available at https://github.com/goauthentik/authentik/blob/e476db13e56addcb88a3170ba27ce7dd0ddc5c6b/authentik/root/channels.py
It would be great if that part of the code was a bit re-organised so that overriding the backend is easier.
Oh I forgot, but as with the other thing, I'm happy to open a proposal PR for this.
This is an Interesting use case that I didn't think about.
I think subclassing is the way to go (rather than adding a new config parameter) since this is a niche use case. but you shouldn't need to do it for both classes.
Subclassing the PostgresChannelLayer should be enough because it calls DatabaseWrapper and then passes the resulting db_params into the DatabaseLayer class
I can see that you also keep the same convention in your code with:
self.django_db = DatabaseLayer(self.django_db.psycopg_options, self.db_params)