TypeError: additional arguments should be named _, got ‘autoload’
The error message “TypeError: additional arguments should be named <dialectname>_<argument>, got ‘autoload'” occurs when the wrong argument is passed to a function that expects named arguments, specifically for a database dialect.
In database programming, different dialects can have variations in the way functions or methods accept arguments. Some functions require named arguments with a specific naming convention. In this case, the function expects an argument with the format “
Let’s understand this error with an example:
import sqlalchemy as sa
# Create a PostgreSQL connection
engine = sa.create_engine('postgresql://username:password@localhost:5432/mydatabase', autoload=True)
In the above example, we are using the SQLAlchemy library to create a PostgreSQL connection. The function sa.create_engine
is used to create an engine object that will handle the database connection. However, we encounter the mentioned error.
The error occurs because we misunderstood the use of the ‘autoload’ argument. Instead of passing it as a positional argument, we should provide it as a named argument with the dialect name prefix:
import sqlalchemy as sa
# Create a PostgreSQL connection with correct arguments
engine = sa.create_engine('postgresql://username:password@localhost:5432/mydatabase', postgresql_autoload=True)
In the corrected example, we are using the correct named argument ‘postgresql_autoload’ instead of the incorrect positional argument ‘autoload’. By using the correct argument name, we avoid the TypeError.