Skip to content

Commit 9e5ad1f

Browse files
authored
Apply rabbit suggestions on the e2e feature branch (OWASP#3389)
* Update dump_data * Apply rabbit suggestions * Update tests and dump_data command * Update update-nest-test-images.yaml
1 parent 1766a82 commit 9e5ad1f

File tree

14 files changed

+58
-43
lines changed

14 files changed

+58
-43
lines changed

.github/workflows/update-nest-test-images.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ jobs:
8282
cache-to: |
8383
type=gha,compression=zstd
8484
type=registry,ref=owasp/nest:test-fuzz-backend-cache
85-
context: backend/docker
86-
file: Dockerfile.fuzz
85+
context: backend
86+
file: docker/backend/Dockerfile.fuzz
8787
platforms: linux/amd64
8888
push: true
8989
tags: owasp/nest:test-fuzz-backend-latest

backend/apps/common/management/commands/dump_data.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from django.conf import settings
99
from django.core.management.base import BaseCommand, CommandError
10-
from psycopg2 import ProgrammingError, connect, sql
10+
from psycopg2 import OperationalError, ProgrammingError, connect, sql
1111

1212
DEFAULT_DATABASE = settings.DATABASES["default"]
1313
DB_HOST = DEFAULT_DATABASE.get("HOST", "localhost")
@@ -52,7 +52,14 @@ def handle(self, *args, **options):
5252

5353
temp_db = f"temp_{DB_NAME}"
5454
try:
55-
self._execute_sql("postgres", [f"CREATE DATABASE {temp_db} TEMPLATE {DB_NAME};"])
55+
self._execute_sql(
56+
"postgres",
57+
[
58+
sql.SQL("CREATE DATABASE {temp_db} TEMPLATE {DB_NAME};").format(
59+
temp_db=sql.Identifier(temp_db), DB_NAME=sql.Identifier(DB_NAME)
60+
)
61+
],
62+
)
5663

5764
self.stdout.write(self.style.SUCCESS(f"Created temporary DB: {temp_db}"))
5865

@@ -86,20 +93,27 @@ def handle(self, *args, **options):
8693
raise CommandError(message) from e
8794
finally:
8895
try:
89-
self._execute_sql("postgres", [f"DROP DATABASE IF EXISTS {temp_db};"])
90-
except CalledProcessError:
96+
self._execute_sql(
97+
"postgres",
98+
[
99+
sql.SQL("DROP DATABASE IF EXISTS {temp_db};").format(
100+
temp_db=sql.Identifier(temp_db)
101+
)
102+
],
103+
)
104+
except (ProgrammingError, OperationalError):
91105
self.stderr.write(
92106
self.style.WARNING(f"Failed to drop temp DB {temp_db} (ignored).")
93107
)
94108

95-
def _table_list_query(self) -> str:
96-
return """
109+
def _table_list_query(self) -> sql.Composable:
110+
return sql.SQL("""
97111
SELECT table_name
98112
FROM information_schema.columns
99113
WHERE table_schema = 'public' AND column_name = 'email';
100-
"""
114+
""")
101115

102-
def _remove_emails(self, tables: list[str]) -> list[str]:
116+
def _remove_emails(self, tables: list[str]) -> list[sql.Composable]:
103117
return [
104118
sql.SQL("UPDATE {table} SET email = '';").format(table=sql.Identifier(table))
105119
for table in tables
@@ -108,7 +122,7 @@ def _remove_emails(self, tables: list[str]) -> list[str]:
108122
def _execute_sql(
109123
self,
110124
dbname: str,
111-
sql_queries: list[str],
125+
sql_queries: list[sql.Composable],
112126
):
113127
connection = connect(
114128
dbname=dbname,

backend/apps/github/api/internal/nodes/pull_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ def repository_name(self, root: PullRequest) -> str | None:
3838
@strawberry_django.field
3939
def url(self, root: PullRequest) -> str:
4040
"""Resolve URL."""
41-
return root.url or ""
41+
return root.url

backend/apps/github/api/internal/queries/issue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def recent_issues(
4848
"""Resolve recent issues with optional filtering.
4949
5050
Args:
51-
distinct (bool): Whether to return unique issues per author and repository.
51+
distinct (bool): Whether to return unique issues per author.
5252
limit (int): Maximum number of issues to return.
5353
login (str, optional): Filter issues by a specific author's login.
5454
organization (str, optional): Filter issues by a specific organization's login.

backend/apps/github/api/internal/queries/pull_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def recent_pull_requests(
4949
"""Resolve recent pull requests.
5050
5151
Args:
52-
distinct (bool): Whether to return unique pull requests per author and repository.
52+
distinct (bool): Whether to return unique pull requests per author.
5353
limit (int): Maximum number of pull requests to return.
5454
login (str, optional): Filter pull requests by a specific author's login.
5555
organization (str, optional): Filter pull requests by a specific organization's login.

backend/apps/github/api/internal/queries/release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def recent_releases(
3333
"""Resolve recent releases with optional distinct filtering.
3434
3535
Args:
36-
distinct (bool): Whether to return unique releases per author and repository.
36+
distinct (bool): Whether to return unique releases per author.
3737
limit (int): Maximum number of releases to return.
3838
login (str, optional): Filter releases by a specific author's login.
3939
organization (str, optional): Filter releases by a specific organization's login.

backend/apps/github/api/internal/queries/user.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def top_contributed_repositories(
3737
.order_by("-contributions_count")
3838
]
3939

40-
@strawberry_django.field(select_related=["owasp_profile", "user_badges__badge"])
40+
@strawberry_django.field(
41+
select_related=["owasp_profile"], prefetch_related=["user_badges__badge"]
42+
)
4143
def user(
4244
self,
4345
login: str,

backend/apps/owasp/api/internal/nodes/committee.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def contributors_count(self, root: Committee) -> int:
1616
return root.owasp_repository.contributors_count if root.owasp_repository else 0
1717

1818
@strawberry_django.field
19-
def created_at(self, root: Committee) -> float:
19+
def created_at(self, root: Committee) -> float | None:
2020
"""Resolve created at."""
2121
return root.idx_created_at
2222

backend/apps/owasp/api/internal/queries/post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ class PostQuery:
1515

1616
@strawberry_django.field
1717
def recent_posts(self, limit: int = 5) -> list[PostNode]:
18-
"""Return the 5 most recent posts."""
18+
"""Return the most recent posts."""
1919
return Post.recent_posts()[:limit] if (limit := min(limit, MAX_LIMIT)) > 0 else []

backend/apps/owasp/models/project_health_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def owasp_page_last_update_days_requirement(self) -> int:
149149
@cached_property
150150
def project_requirements(self) -> ProjectHealthRequirements | None:
151151
"""Get the project health requirements for the project's level."""
152-
return ProjectHealthRequirements.objects.get(level=self.project.level)
152+
return ProjectHealthRequirements.objects.filter(level=self.project.level).first()
153153

154154
@staticmethod
155155
def bulk_save(metrics: list, fields: list | None = None) -> None: # type: ignore[override]

0 commit comments

Comments
 (0)