mongodb-labs / django-mongodb

MongoDB Backend for Django
Apache License 2.0
16 stars 7 forks source link

make ObjectIdAutoField.to_python() accept integers as strings #175

Closed timgraham closed 1 month ago

timgraham commented 1 month ago

There are at least two places in Django where Field.to_python() processes uncoerced form data, BaseModelFormSet._construct_form() and ModelAdmin.get_object().

Jibola commented 1 month ago

Hrm, why should this silently accept an int conversion on the autofield? I understand that uncoerced data comes through the form construction, but wouldn't this be breaking assumptions on ObjectId types?

timgraham commented 1 month ago

This is a continuation of https://github.com/mongodb-labs/django-mongodb/pull/105#discussion_r1719170263.

Jibola commented 1 month ago

Ahhhh, thanks for the reminder.

Now that it's called "ObjectIdAutoField" rather than "MongoAutoField" I imagine this could lead to some confusion. Nonetheless, let's add the change in, but could you add a comment above including this ticket? https://jira.mongodb.org/browse/INTPYTHON-393

I don't think it's an issue now, nor is this a bad solution. I would want to revisit the semantics of this at a later date.