Skip to content

Conversation

obayemi
Copy link
Contributor

@obayemi obayemi commented Oct 23, 2020

treebeard was expecting the primary key for models to be integer serials

fixed two problems

  1. detection of insertion was checking if the pk was None, but with custom ids with default values (as with uuids) the pk is never None as the default is set at model init. changed all checks to use more reliable model._state.adding instead.
  2. the forms forced the use of integer as reference id, so it triggered an error when sending an uuid. I used the model field's formfield to_python as coerce function if applicable.

I also added tests but let me know if I should add more tests.

@obayemi
Copy link
Contributor Author

obayemi commented Oct 23, 2020

oh, I just noticed that was already mostly fixed by #93 ... Should i delete it ?
The only real difference is that I kept the TypedChoiceField and used the id fields's formfield as a coersion method and that I don't check for both instance pk and _state.adding

EDIT: also changed the "default id" assigned to the "root" element to None instead of 0 to be have a more consistent "Null-ish" value across different types

@obayemi
Copy link
Contributor Author

obayemi commented Oct 26, 2020

also set the "root" / reference node to None in the forms for a more reliable behaviour across different types.

@johanneswilm johanneswilm mentioned this pull request Jan 15, 2021
@tabo tabo merged commit 6d1a77b into django-treebeard:master Jan 16, 2021
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.

2 participants