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

no way to prefix query DateTime #150

Open
numberoverzero opened this issue Nov 15, 2021 · 0 comments
Open

no way to prefix query DateTime #150

numberoverzero opened this issue Nov 15, 2021 · 0 comments
Assignees
Milestone

Comments

@numberoverzero
Copy link
Owner

from bloop import BaseModel, DateTime, String, Column, Engine

class MyModel(BaseModel):
    id = Column(String, hash_key=True)
    date = Column(DateTime, range_key=True)

e = Engine()
e.bind(MyModel, skip_table_setup=True)

condition_hk = MyModel.id == "foo"
condition_rk = MyModel.date.begins_with("2021-11")
condition = condition_hk & condition_rk

# this line fails:
# AttributeError: 'str' object has no attribute 'in_timezone'
q = e.query(MyModel, condition)

This is because DateTime assumes only a datetime.datetime instance will be passed through dynamo_dump but for the begins_with condition we'll often pass a string prefix of the serialized datetime object. For example, filtering on a datetime range key to a single month.

One possible solution is to pass an additional field(s) through the context. Some rough first drafts:

rendering query condition
{
    "engine": Engine,
    "some key tbd": "engine.query",
    "condition": <BeginsWithCondition object>,
    "query": <Query object>,
}

rendering transactional read key
{
    "engine": Engine,
    "some key tbd": "tx.read",
    "tx": <Transaction object>,
    "tx_item": <TxItem object>,
}

rendering transactional write condition
{
    "engine": Engine,
    "some key tbd": "tx.write",
    "tx": <Transaction object>,
    "tx_item": <TxItem object>,
}

rendering keys for Engine.load
{
    "engine": Engine,
    "some key tbd": "engine.load",
    "obj": <object being loaded into>,
}

Today, only "engine" is required. The additional fields would vary based on what high-level operation is happening, and there's some unpacking we should do for ease of use (eg. point at each item in the AndCondition instead of the AndCondition itself).

To find all call sites, look for Type._dump or Type._load. Specifically look for calls to:

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

No branches or pull requests

1 participant