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

Using SQL functions for default values doesn't work with dataclass record insertion API #60

Open
ozpau opened this issue Mar 8, 2025 · 1 comment · May be fixed by AnswerDotAI/apswutils#20

Comments

@ozpau
Copy link

ozpau commented Mar 8, 2025

See this notebook for the demonstration of the issue: https://github.com/ozpau/fastlite_dataclass_default_functional/blob/main/nbs/00_core.ipynb

Or this quarto rendered page if you prefer: https://ozpau.github.io/fastlite_dataclass_default_functional/core.html

@ozpau
Copy link
Author

ozpau commented Mar 8, 2025

Part of the reason is the last line in apswutils.db._decode_default_value:

def _decode_default_value(value):
    if value.startswith("'") and value.endswith("'"):
        # It's a string
        return value[1:-1]
    if value.isdigit():
        # It's an integer
        return int(value)
    if value.startswith("X'") and value.endswith("'"):
        # It's a binary string, stored as hex
        to_decode = value[2:-1]
        return binascii.unhexlify(to_decode)
    # If it is a string containing a floating point number:
    try:
        return float(value)
    except ValueError:
        pass
    return value

The different between strings and SQL functions is that strings are quoted, but after this function executes we no longer pass forward any information on whether the original value was a string or a function.

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

Successfully merging a pull request may close this issue.

1 participant