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

[WIP] Support null values for optional fields #340

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

wiseaidev
Copy link
Contributor

@wiseaidev wiseaidev commented Aug 9, 2022

Related to #261 & #254

The query is working, the only issue is that the await model.save() call returns the values stored in Redis, i also need to apply this workaround to this method that i am currently trying to find out how.

The string zero "0" is the null value rather than the empty string cause it is a valid int and float, not sure if someone want to store "0" in the database as a string value, highly unlikely.

Test case example:

actual = await (m.Member.find(m.Member.bio % "great").all()) # Notice the None values.

[Member(pk='01GA23KQ9SSGK1TNVZD202C9RM', id=0, first_name='Andrew', last_name='Brookins', email='[email protected]', join_date=datetime.date(2022, 8, 9), height=None, weight=None, age=38, bio='This is member 1 whose greatness makes him the life and soul of any party he goes to.')]

       
member1 = m.Member(
  id=0,
  first_name="Andrew, the Michael",
  last_name="St. Brookins-on-Pier",
  email="a|[email protected]",  # NOTE: This string uses the TAG field separator.
  age=38,
  join_date=today,
  bio="This is a test user on our system.",
)
await member1.save()

# returns zeros rather than Nones
[Member(pk='01GA23KQ9SSGK1TNVZD202C9RM', id=0, first_name='Andrew', last_name='Brookins', email='[email protected]', join_date=datetime.date(2022, 8, 9), height=0, weight=0.0, age=38, bio='This is member 1 whose greatness makes him the life and soul of any party he goes to.')]

I think the only solution is to override self or construct a new object with these values(None in place of "0").

Signed-off-by: wiseaidev <[email protected]>
@wiseaidev wiseaidev force-pushed the fix-optional-fields branch 4 times, most recently from f260efe to c483098 Compare August 10, 2022 16:15
Signed-off-by: wiseaidev <[email protected]>
@dvora-h
Copy link
Contributor

dvora-h commented Aug 11, 2022

@wiseaidev It doesn't seem to have solved the problem, the tests are failing.

@wiseaidev
Copy link
Contributor Author

Hey @dvora-h, sorry, i was AFK. Working on it, not finished yet! Marking it as a work in progress!

@wiseaidev wiseaidev changed the title Support null values for optional fields [WIP] Support null values for optional fields Aug 11, 2022
@sav-norem
Copy link

Wanted to add a comment - seems like you're aware based on the tests only being for the HashModel, but to call it out, issues #254 and #261 work if you swap the HashModel for a JsonModel - not a fix, but something to note and call out.

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 this pull request may close these issues.

None yet

3 participants