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
handle crash on start-up when change_list_template
is a property
#1523
handle crash on start-up when change_list_template
is a property
#1523
Conversation
…export into issue-1521
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I hand-applied the patch and, as expected, my
Here is the thing: prior to release 3, the Admin support for exporting this model worked just fine, producing files like this: Now, I get the exception, and these buttons don't show up either: From my point of view (i.e. not as the developer of this code :-)), ideally:
So should failing to set this attribute really be fatal? Can the old behaviour not work? |
Thanks for testing. All very good points. I'll take a look. |
hi @ShaheedHaque I had another look, and have come up with the following
class CompanyPostalDetailAdmin(ImportExportMixin, poly_parentadmin.PolymorphicParentModelAdmin):
change_list_template = 'admin/import_export/change_list_export.html' I think this is a fair compromise between handling errors generated from integration alongside other libraries, and allowing flexibility for customisation. Please could you try the latest changes and let me know what you think. |
Thanks again for you prompt assistance. I tried your suggestion to override the attribute by subclassing your mixin like this (I tried both versions as per the commented out line):
but Django crapped out saying TemplateDoesNotExist and producing this postmortem:
Surprised? I was! I feel I am missing something obvious...but I just cannot see it. |
Sounds similar to #1514. I have been able to reproduce this now. To resolve, try this: class CompanyPostalDetailAdmin(ImportExportMixin, poly_parentadmin.PolymorphicParentModelAdmin):
import_export_change_list_template = "admin/import_export/change_list_export.html" |
OK, based on your last observation, I first tried your suggestion ~verbatim, and of course that gave me the original exception because the @property-decorated attribute was still in play. I then thought a bit harder, and realised that if I did this:
then, hey-presto, the @property-decorated attribute is no longer in play (and of course, there is actually no need to muck about with So, I guess it is your call whether to bother with this patch or not...I'm happy for the issue to be closed as you see fit. Either way, many many thanks for patiently walk me to this point. |
but presumably would be ok now because we are catching the exception and logging. I guess you want to avoid the log statement altogether.
I think it will be useful to add it in - it will be much better for anyone in future not to have the app crash on start up. I've added the method
No problem - it's been useful for me to understand this issue in more detail, so thanks for providing the updates. |
- Based on django-import-export/django-import-export#1523 (comment) - The 'change_list_template' parameter must be defined when a Import/Export mixin is used in conjunction with some other mixins.
Problem
Fix for issue #1521. The server crashes when attempting to assign
change_list_template
if this has been decorated as a property in another library. This is a workaround for issues which can arise when integrating import-export along with other libraries.Solution
The
AttributeError
is caught and an exception is logged. This doesn't crash the process and will give the user the opportunity to investigate and resolve. I investigated testing if the attribute is implemented as a property, but this did not work. It never evaluated the attribute as a property, only as a list.Acceptance Criteria