When using sqlalchemy with multiple dialects, just adding dialect-specific configuration such as sqlite's foreign key support or postgres' server_side_cursors poses a problem, because all other dialects will not understand the configuration or events. For instance:
# applying postgres configuration to a sqlite3 database fails
>>> sqlalchemy.create_engine("sqlite3:///test.sqlite3", server_side_cursors=True)
...
TypeError: Invalid argument(s) 'server_side_cursors' sent to create_engine(), using configuration SQLiteDialect_pysqlite/NullPool/Engine. Please check that the keyword arguments are appropriate for this combination of components.
However, sqlite does not need this configuration, because it automatically streams results. Similarly postgres does not need to enable foreign key support, because that's the default.
How can I apply this dialect-specific configuration in a way, that does not break other dialects? Is there some sqlalchemy facilitating this branching? Is there something better than isinstance
tests?