Skip to content

Conversation

zeth
Copy link

@zeth zeth commented Apr 26, 2025

Made BaseInlineFormSet explicitly support auto_id, for consistency with the prefix argument and superclasses.

Trac ticket number

ticket-14688

Branch description

BaseInlineFormSet.init does not explicitly accept the auto_id argument, unlike its ancestor classes, and thus inconsistent with its sibling argument prefix.

This is picking up word already done by Victor Andrée and Tobias Kunze, with a longer and more specific test. The ticket was closed by mistake and then the ticket was reopened.

This is one of two approaches, the other would be to make prefix not an explicit argument to match auto_id, but that would be a breaking change.

No idea if anyone still wants this or cares 14 years after first opening, but this should hopefully push the ticket forward at least.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

…nsistency (with "prefix" argument and ancestors).
@zeth zeth marked this pull request as ready for review April 26, 2025 11:42
Copy link
Contributor

@fsbraun fsbraun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeth Looks good to me.

Unfortunately, BaseModelFormSet has a positional argument auto_id at position 3. Hence, I would like to suggest to not allow auto_id as a positional argument at a different position in BaseInlineFormSet. Instead let it go into the named arguments.

save_as_new=False,
prefix=None,
queryset=None,
auto_id="id_%s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto_id="id_%s",

I suggest to let this go into kwargs.

self.unique_fields = {self.fk.name}
super().__init__(data, files, prefix=prefix, queryset=qs, **kwargs)
super().__init__(
data, files, prefix=prefix, queryset=qs, auto_id=auto_id, **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data, files, prefix=prefix, queryset=qs, auto_id=auto_id, **kwargs
data, files, prefix=prefix, queryset=qs, **kwargs

... then the auto_id will be passed on within the kwargs.


# Using positional argument
inlineformset = PoemInlineFormSet(
None, None, poet, False, None, None, "id_custom_%s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
None, None, poet, False, None, None, "id_custom_%s"
None, None, poet, False, None, None, auto_id="id_custom_%s"

In the test, we would need to pass the auto_id not as a named argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants