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

snapshot-setup #809

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

Conversation

yashgoyal0110
Copy link
Contributor

fixes: #800

@yashgoyal0110 yashgoyal0110 force-pushed the fix/snapshot-setup branch 2 times, most recently from 8232789 to 4b687e5 Compare February 11, 2025 19:35
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

I strongly suggest reconsidering the approach of working on tasks in general.

Please also add a minimal test coverage.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this file.

"""Get items created or updated within the snapshot timeframe."""
return model.objects.filter(
Q(created_at__gte=snapshot.start_at, created_at__lte=snapshot.end_at)
| Q(updated_at__gte=snapshot.start_at, updated_at__lte=snapshot.end_at)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need new items only.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The migration for this is missing.

"""Model representing a snapshot of data processing."""

class Status(models.TextChoices):
PENDING = "pending", _("Pending")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't do l10n yet.

Comment on lines 23 to 28
# Many-to-Many relationships
new_chapters = models.ManyToManyField("Chapter", related_name="snapshots", blank=True)
new_projects = models.ManyToManyField("Project", related_name="snapshots", blank=True)
new_issues = models.ManyToManyField("GitHubIssue", related_name="snapshots", blank=True)
new_releases = models.ManyToManyField("GitHubRelease", related_name="snapshots", blank=True)
new_users = models.ManyToManyField("GitHubUser", related_name="snapshots", blank=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code won't work as GitHubIssue and other entities you referring to just don't exist. I expect a better quality of PRs for GSoC grade tasks. Please at least run your code locally.

@yashgoyal0110
Copy link
Contributor Author

Hey @arkid15r

  • Test files are added
  • Migrations are generated
  • file names are corrected
  • unwanted files are removed
  • code checked on local

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

This looks better but I haven't run this code yet. Please look into these when you get a chance:

error_message = models.TextField(blank=True)

# Many-to-Many relationships
new_chapters = models.ManyToManyField("Chapter", related_name="snapshots", blank=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make it owasp.Chapter for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes made 👍

),
],
)
def test_str_representation(start_at, end_at, status, expected_str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use a class here too?

Copy link
Contributor Author

@yashgoyal0110 yashgoyal0110 Feb 17, 2025

Choose a reason for hiding this comment

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

made the changes 👍

Comment on lines 63 to 69
class SnapshotAdmin(admin.ModelAdmin):
list_display = ("start_at", "end_at", "status", "created_at", "updated_at")
list_filter = ("status", "start_at", "end_at")
search_fields = ("status", "error_message")
ordering = ("-start_at",)


Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you keep the formatting/style consistent with the current one? I mean the new class position within other classes and tuple formatting.

error_msg = f"Failed to process snapshot: {e}"
raise SnapshotProcessingError(error_msg) from e

def get_new_items(self, model, snapshot):
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need start/end dates only instead of the entire snapshot.


start_at = models.DateTimeField()
end_at = models.DateTimeField()
status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't 20 too much?

status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
error_message = models.TextField(blank=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

also add default=""

Comment on lines 30 to 34
ordering = ["-start_at"]
indexes = [
models.Index(fields=["status"]),
models.Index(fields=["start_at", "end_at"]),
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove these and add db_table and verbose_name_plural that we use for in other models.

Comment on lines 28 to 29
snapshot.__str__.return_value = expected_str
assert str(snapshot) == expected_str
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test doesn't make sense as you mock the __str__ and compare it with the value you return. You need to actually test the code of Snapshot model

Comment on lines 34 to 35
snapshot.status = "pending"
assert snapshot.status == "pending"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, please make sure to test actual application code.

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.

Implement initial OWASP Snapshots support
3 participants