Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompileError at update_many due to column in a dataset doesn't exist in a db #409

Open
4l1fe opened this issue Jan 3, 2023 · 2 comments

Comments

@4l1fe
Copy link

4l1fe commented Jan 3, 2023

Got this error while updating a dataset. It's not a big deal and i called the method create_column() to update a table schema,but it's somewhat out of the Dataset concept i guess, columns are created on the go.

As i see, there is the relative issue #352 and the fact that update_many() doesn't handle ensure keyword argument at all.

I think a way to improve the insert_many(), upsert_many(), update_many() methods is to add a new wrapper _sync_columns_many() and move there the block of code:

        # Sync table before inputting rows.
        sync_row = {}
        for row in rows:
            # Only get non-existing columns.
            sync_keys = list(sync_row.keys())
            for key in [k for k in row.keys() if k not in sync_keys]:
                # Get a sample of the new column(s) from the row.
                sync_row[key] = row[key]
        self._sync_columns(sync_row, ensure, types=types)

What do you think about? It doesn't look difficult to fix and i could implement it, gratefully tests are on the place.

@czertyaka
Copy link

I've also encountered into this. It seems that MetaData constructor from SQLAlchemy does not support bind keyword argument anymore.
main branch:

class MetaData(HasSchemaAttr):
    def __init__(
        self,
        schema: Optional[str] = None,
        quote_schema: Optional[bool] = None,
        naming_convention: Optional[Dict[str, str]] = None,
        info: Optional[_InfoType] = None,
    ) -> None:

It was already marked as deprecated in release 1.4:

class MetaData(SchemaItem):
    @util.deprecated_params(
        bind=(
            "2.0",
            "The :paramref:`_schema.MetaData.bind` argument is deprecated and "
            "will be removed in SQLAlchemy 2.0.",
        ),
    )
    def __init__(
        self,
        bind=None,
        schema=None,
        quote_schema=None,
        naming_convention=None,
        info=None,
    ):

@vladiscripts
Copy link

Now the code breaks with a critical error raised:

db['tbl'].all()

TypeError: MetaData.__init__() got an unexpected keyword argument 'bind'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants