Open unique1o1 opened 9 months ago
Hi @unique1o1 could you define "doesn't work" - does it give some error ? or behaves differently (how) ?
Hi @unique1o1 could you define "doesn't work" - does it give some error ? or behaves differently (how) ?
Hey, @vitalik
Yeah, it gives an error saying TypeError: cannot specify both default and default_factory
It seems this might be because when optional
is set, it only sets default = None
, but doesn't also set default_factory = None
.
There is a space before 'answers' in your quote:
fields_optional = [
'certificate',
'topic',
'question',
'image',
'question_type',
'answers', <----------------but removing the this will then work.
'correct_answer',
]
Sometimes parsers are demanding. Check if the space removal fixes the bug.
i'm having the exact same issue. i'm creating all my write schemas this way :
class OrderWriteSchema(create_schema(Order, optional_fields="__all__")):
pass
but for one very specific models, i'm having the TypeError: cannot specify both default and default_factory
error.
I finally found the problematic field in my model, it's this one :
default_order_datas = models.JSONField(null=False, default=dict)
I made the field nullable and removed the default factory and the error disappeared.
It looks like #1019 should have fixed this, can you check this again on the latest release?
I'm unable to use
fields_optional='__all__'
in some models?here are my models:
Schema:
Using
fields_optional='__all__'
in QuestionUpdateSchema does not work but it works in TopicUpdateSchema. Even adding the following fields in QuestionUpdateSchema didn't work .but when i remove
answers
field from fields_optional it starts working.Versions