-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
get_or_create
raises ValueError
#1152
Comments
Hmm, I'm not sure - your code looks OK to me. I created this reproducible example: import asyncio
from piccolo.table import Table, create_db_tables
from piccolo.columns import ForeignKey, Varchar, Serial
from piccolo.engine.postgres import PostgresEngine
DB = PostgresEngine({
"database": "piccolo_get_or_create"
})
class Group(Table, db=DB):
id: Serial
name = Varchar()
class Account(Table, db=DB):
id: Serial
name = Varchar()
class GroupMember(Table, db=DB):
id: Serial
group_id = ForeignKey(references=Group, index=True, null=False)
account_id = ForeignKey(references=Account, index=True, null=False)
async def main():
await create_db_tables(Group, Account, GroupMember, if_not_exists=True)
group = Group()
await group.save()
account = Account()
await account.save()
await GroupMember.objects().get_or_create(
(
GroupMember.group_id == group.id
) & (
GroupMember.account_id == account.id
)
)
if __name__ == '__main__':
asyncio.run(main()) It could be a bug - I would use one of the other syntaxes for now while we investigate. |
@dantownsend The Lines 435 to 440 in 8fd69e7
The default value for FK columns is always |
@sinisaos Interesting - so it's something to do with having It looks like this is the problem: piccolo/piccolo/query/methods/objects.py Line 68 in 8fd69e7
If we change it to this, then it works: instance = self.table_class(_data=self.defaults, _ignore_missing=True) By default, when instantiating a Rather than setting
|
get_or_create
raises ValueError
Sorry, a suggestion that is off topic: |
python_version: 3.13.1
piccolo-orm version: 1.22.0
I created the following table:
Then:
I don't know why.
The text was updated successfully, but these errors were encountered: