Repository navigation
Conversation
3966ee5 to
35858e1
Compare
|
|
||
| user = BaseUser.objects(exclude_secrets=True).first().run_sync() | ||
| assert user is not None | ||
| assert user.password is None |
There was a problem hiding this comment.
Should we compare to None or to something else? Such as ...?
|
|
||
| user = BaseUser.objects(exclude_secrets=True).first().run_sync() | ||
| assert user is not None | ||
| assert user.password is None |
There was a problem hiding this comment.
The test is not passing because password has a default value being an empty string (that is then hashed). The default value is affected at Table class initialization:
Lines 492 to 505 in fc1fc86
... being called from Query:
Lines 122 to 128 in fc1fc86
An option would be to set _ignore_missing argument to True and to only consume the default value if _ignore_missing is True. But I am not sure about other impacts this could have?
There was a problem hiding this comment.
Ok, I have just tried this implementation.
| ): | ||
| raise ValueError(f"{column._meta.name} wasn't provided") | ||
|
|
||
| self[column._meta.name] = value |
There was a problem hiding this comment.
If ... as a default value is not ok, what about turning this into:
if value is not ...:
self[column._meta.name] = valueHowever, it means that the column may not be available in self so the __get__ method in piccolo/columns/column_types.py has to be adapted accordingly.
|
I think the challenge with class User(Table):
name = Varchar()
password = Varchar(secret=True)
user = await User.objects(exclude_secrets=True).first()By excluding secrets, would password be set to If we then save the object, it has the potential to override the stored password. await user.save()So we'd have to assign something like |
That is exactly what I am wondering in my previous comments. 🙂 For now, I'm leaning towards
That's a good catch! It is exactly what is breaking tests for now. I am going to try to complete |
Yes, something like |
| i: getattr(self, i._meta.name, None) for i in column_instances | ||
| } | ||
|
|
||
| if self._ignore_missing: |
There was a problem hiding this comment.
Here is a proposition for the save method. However, I am not entirely satisfied of reusing _ignore_missing. What about introducing a parameter _ignore_secrets that would be used in the Table initialization?
There was a problem hiding this comment.
Indeed, it is breaking the ModelBuilder...
As for
Selectquery, it addsexclude_secretstoObjectsquery.