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

ERA001 skipping some lines #1542

Closed
sbdchd opened this issue Jan 2, 2023 · 2 comments · Fixed by #1559
Closed

ERA001 skipping some lines #1542

sbdchd opened this issue Jan 2, 2023 · 2 comments · Fixed by #1559
Assignees
Labels
bug Something isn't working

Comments

@sbdchd
Copy link
Contributor

sbdchd commented Jan 2, 2023

I have the following code:

def backfill(apps: Any, schema_editor: Any) -> None:
    """
    Create TimelineEvents for everything
    """
    db_alias = schema_editor.connection.alias

    Recipe = apps.get_model("recipeyak", "Recipe")
    TimelineEvent = apps.get_model("recipeyak", "TimelineEvent")

    # user_content_type, _ = TimelineEvent.objects.using(db_alias).get_or_create(
    #     app_label="core", model="user"
    # )
    timeline_events = []
    for recipe in Recipe.objects.using(db_alias).all():
        timeline_events.append(
            TimelineEvent(
                action="created", created_by=None, recipe=recipe, created=recipe.created
            )
        )
        if recipe.archived_at:
            timeline_events.append(
                TimelineEvent(
                    action="archived",
                    created_by=None,
                    recipe=recipe,
                    created=recipe.archived_at,
                )
            )
    TimelineEvent.objects.using(db_alias).bulk_create(timeline_events)

and the auto fix generates the following diff (which is missing a line):

diff --git a/backend/recipeyak/migrations/0089_backfill_timeline.py b/backend/recipeyak/migrations/0089_backfill_timeline.py
index 7c7bf670..4d99ae38 100644
--- a/backend/recipeyak/migrations/0089_backfill_timeline.py
+++ b/backend/recipeyak/migrations/0089_backfill_timeline.py
@@ -15,8 +15,6 @@ def backfill(apps: Any, schema_editor: Any) -> None:
     TimelineEvent = apps.get_model("recipeyak", "TimelineEvent")
 
     # user_content_type, _ = TimelineEvent.objects.using(db_alias).get_or_create(
-    #     app_label="core", model="user"
-    # )
     timeline_events = []
     for recipe in Recipe.objects.using(db_alias).all():
         timeline_events.append(

Edit: it's not the auto fix, I think the issue is it's not detecting the first line s commented out code

@sbdchd sbdchd changed the title ERA001 auto fix skipping some lines ERA001 skipping some lines Jan 2, 2023
@charliermarsh charliermarsh added the bug Something isn't working label Jan 2, 2023
@charliermarsh
Copy link
Member

Does look like a bug. I have to look at the rules for detection to understand what’s going on. It might also be worth checking if the originating eradicate library catches those lines, but I can do that when I debug.

@charliermarsh
Copy link
Member

eradicate doesn't catch this either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants