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

import modes not working for write operations #33

Open
sidphbot opened this issue Nov 5, 2021 · 0 comments
Open

import modes not working for write operations #33

sidphbot opened this issue Nov 5, 2021 · 0 comments

Comments

@sidphbot
Copy link

sidphbot commented Nov 5, 2021

code snippet to reproduce:
via doltcli
write_rows(write_rows(dolt, "characters", TEST_ROWS, REPLACE, ["id"])

or via doltpy:
write_pandas(dolt, table_name, df, import_mode='replace')

both call _import_helper which refers to

doltcli/doltcli/utils.py

Lines 251 to 265 in a807c93

def _get_import_mode_and_flags(
dolt: DoltT, table: str, import_mode: Optional[str] = None
) -> str:
import_modes = IMPORT_MODES_TO_FLAGS.keys()
if import_mode and import_mode not in import_modes:
raise ValueError(f"update_mode must be one of: {import_modes}")
else:
if table in [table.name for table in dolt.ls()]:
logger.info(f'No import mode specified, table exists, using "{UPDATE}"')
import_mode = UPDATE
else:
logger.info(f'No import mode specified, table exists, using "{CREATE}"')
import_mode = CREATE
return import_mode

the checks force it to return only create/update mode depending on the existence of the table, replace/force-create modes are ignored

suggested change (MR #32 ) :

def _get_import_mode_and_flags(
    dolt: DoltT, table: str, import_mode: Optional[str] = None
) -> str:
    import_modes = IMPORT_MODES_TO_FLAGS.keys()
    if import_mode and import_mode not in import_modes:
        raise ValueError(f"update_mode must be one of: {import_modes}")
    elif import_mode:
        return import_mode
    else:
        if table in [table.name for table in dolt.ls()] and import_mode :
            logger.info(f'No import mode specified, table exists, using "{UPDATE}"')
            import_mode = UPDATE
        else:
            logger.info(f'No import mode specified, table exists, using "{CREATE}"')
            import_mode = CREATE

    return import_mode
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

1 participant