Closed adamchainz closed 3 months ago
Hum that's weird, I tried to add the following test and it passed :thinking:
def test_duplicated_class_definition():
check_transformed(
"""\
from django.contrib import admin
class BookAdmin(admin.ModelAdmin):
pass
class BookAdmin(admin.ModelAdmin):
pass
admin.site.register(Book, BookAdmin)
""",
"""\
from django.contrib import admin
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
pass
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
pass
""",
)
Oh, thank you for trying. I simplified it out of a project I was just helping out on. I will check to see if there are any other relevant details I missed.
Right, the failure was actually:
class BookAdmin(admin.ModelAdmin):
...
- admin.site.register(Book, BookAdmin)
class BookAdmin(admin.ModelAdmin):
...
I’m going to adjust the fixer to bail when a duplicate definition is found.
Currently the fixer does this:
The registration is unsafely removed.