Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor invalid method declarations #1566

Conversation

matthewhegarty
Copy link
Contributor

@matthewhegarty matthewhegarty commented Mar 17, 2023

Problem

Some of the methods are declared incorrectly. A named parameter appears before the *args declaration which is invalid (e.g. #1565).

Solution

Refactor the methods and add deprecation warnings where appropriate.

Where named parameters were declared before args, I have corrected the method definition, so that args is the first argument. If users have overridden these methods, they will need to update, but I have added checks to ensure backwards compatibility. This is to handle cases where the user is passing the arg as the first param.

Acceptance Criteria

Tests and documentation included.

@coveralls
Copy link

coveralls commented Mar 17, 2023

Coverage Status

Coverage: 100.0%. Remained the same when pulling d5ba677 on matthewhegarty:1565-method-declarations-invalid into ce74bb8 on django-import-export:main.

@matthewhegarty matthewhegarty marked this pull request as ready for review March 23, 2023 11:27
"'queryset' must be supplied as a named parameter",
category=DeprecationWarning
)
queryset = args[0]

Choose a reason for hiding this comment

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

Nice, this is very thoughtful! I actually might have some code fixes to do here in my team's stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have tried to make this change backwards compatible but there may be edge cases which I cannot foresee. It is broken as it is so we have to change it.

Copy link

@pokken-magic pokken-magic left a comment

Choose a reason for hiding this comment

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

Being honest I think we have to rely on tests for this change, but I think it looks good. There're a lot of connections here to be concerned about, but I don't see anything obvious.

@@ -966,10 +966,22 @@ def iter_queryset(self, queryset):
else:
yield from queryset.iterator(chunk_size=self.get_chunk_size())

def export(self, queryset=None, *args, **kwargs):
def export(self, *args, queryset=None, **kwargs):

Choose a reason for hiding this comment

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

I can't help but feel like this is a problem with the interface -- in Java we would probably overload this and have two different export methods I guess, but maybe we should have an export and an export_subset in a future release? I dunno. It just feels wonky.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes good point. There is an additional problem with exports which I hope to address in the near future (see #1548)

@matthewhegarty
Copy link
Contributor Author

Thanks for reviewing - as you say we have to rely on tests, and then fix any other issues which come up.

@matthewhegarty matthewhegarty merged commit 0cefeac into django-import-export:main Mar 23, 2023
6 checks passed
@matthewhegarty matthewhegarty deleted the 1565-method-declarations-invalid branch March 23, 2023 12:06
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.

None yet

3 participants