diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 368a5110aa..cad62f0ab9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace name: trim trailing whitespace @@ -65,7 +65,7 @@ repos: # Versioning: Commit messages & changelog - repo: https://github.com/commitizen-tools/commitizen - rev: v4.6.1 + rev: v4.16.3 hooks: - id: commitizen stages: [commit-msg] @@ -105,15 +105,15 @@ repos: # "!backend/tests/test_data/**", # ] - - repo: https://github.com/psf/black - rev: 25.1.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.5.1 hooks: - id: black language_version: python3.10 - repo: https://github.com/PyCQA/flake8 - rev: "7.2.0" + rev: "7.3.0" hooks: - id: flake8 name: flake8 diff --git a/backend/api/users/tasks.py b/backend/api/users/tasks.py index 7f96eff2dd..b8e399421c 100644 --- a/backend/api/users/tasks.py +++ b/backend/api/users/tasks.py @@ -10,7 +10,6 @@ from typing import Optional - router = APIRouter( prefix="/users", tags=["users"], diff --git a/backend/services/messaging/message_service.py b/backend/services/messaging/message_service.py index 61e6875bc9..7a6260d004 100644 --- a/backend/services/messaging/message_service.py +++ b/backend/services/messaging/message_service.py @@ -546,8 +546,10 @@ async def send_team_join_notification( team_link = MessageService.get_team_link(team_name, team_id, False) user_link = MessageService.get_user_link(from_username) message.subject = f"You have been added to team {team_link}" - message.message = f"You have been added to the team {team_link} as {role} by {user_link}.\ + message.message = ( + f"You have been added to the team {team_link} as {role} by {user_link}.\ Access the {team_link}'s page to view more info about this team." + ) message.date = timestamp() message.read = False user = await UserService.get_user_by_id(to_user, db) diff --git a/backend/services/project_search_service.py b/backend/services/project_search_service.py index 03c485ff62..420617b469 100644 --- a/backend/services/project_search_service.py +++ b/backend/services/project_search_service.py @@ -458,26 +458,20 @@ async def _filter_projects( tsquery_search = " & ".join([x for x in search_text.split(" ") if x]) ilike_search = f"%{search_text}%" - subquery_filters.append( - """ + subquery_filters.append(""" text_searchable @@ to_tsquery('english', :tsquery_search) OR name ILIKE :text_search - """ - ) + """) params["tsquery_search"] = tsquery_search params["text_search"] = ilike_search - filters.append( - """ + filters.append(""" p.id = ANY( SELECT project_id FROM project_info WHERE {} ) - """.format( - " AND ".join(subquery_filters) - ) - ) + """.format(" AND ".join(subquery_filters))) if search_dto.project_statuses: statuses = [ @@ -697,17 +691,13 @@ async def _filter_projects( ) params["partnership_to"] = partnership_to - filters.append( - """ + filters.append(""" p.id = ANY( SELECT pp.project_id FROM project_partnerships pp WHERE {} ) - """.format( - " AND ".join(partner_conditions) - ) - ) + """.format(" AND ".join(partner_conditions))) if search_dto.managed_by and user.role != UserRole.ADMIN.value: project_ids = await ProjectSearchService.get_managed_projects(user.id, db) diff --git a/backend/services/stats_service.py b/backend/services/stats_service.py index 5c87484899..c4cc506226 100644 --- a/backend/services/stats_service.py +++ b/backend/services/stats_service.py @@ -755,26 +755,22 @@ async def get_task_stats( values["org_id"] = int(org_id) if org_name: - filters.append( - """ + filters.append(""" AND organisation_id = ( SELECT id FROM organisations WHERE name = :org_name ) - """ - ) + """) values["org_name"] = org_name if campaign: - filters.append( - """ + filters.append(""" AND id IN ( SELECT project_id FROM campaign_projects WHERE campaign_id = ( SELECT id FROM campaigns WHERE name = :campaign ) ) - """ - ) + """) values["campaign"] = campaign if project_id: @@ -782,15 +778,13 @@ async def get_task_stats( values["project_id"] = project_id if country: - filters.append( - """ + filters.append(""" AND EXISTS ( SELECT 1 FROM unnest(country) AS c WHERE c ILIKE :country ) - """ - ) + """) values["country"] = f"%{country}%" final_query = base_query.format(filters=" ".join(filters)) diff --git a/migrations/versions/451f6bd05a19_.py b/migrations/versions/451f6bd05a19_.py index 8c7f0d66ee..fbbeb6296b 100644 --- a/migrations/versions/451f6bd05a19_.py +++ b/migrations/versions/451f6bd05a19_.py @@ -17,12 +17,10 @@ def upgrade(): op.execute("DROP TRIGGER IF EXISTS tsvectorupdate ON project_info;") - op.execute( - """ + op.execute(""" CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON project_info FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(text_searchable, "pg_catalog.english", project_id_str, short_description, description) - """ - ) + """) def downgrade(): diff --git a/migrations/versions/763165f937cf_.py b/migrations/versions/763165f937cf_.py index 2cb13d06a6..122f87f631 100644 --- a/migrations/versions/763165f937cf_.py +++ b/migrations/versions/763165f937cf_.py @@ -9,7 +9,6 @@ from alembic import op import sqlalchemy as sa - # revision identifiers, used by Alembic. revision = "763165f937cf" down_revision = "4489b9e235f8" diff --git a/migrations/versions/7bbc01082457_.py b/migrations/versions/7bbc01082457_.py index 4ecad17e29..64dcb86c42 100644 --- a/migrations/versions/7bbc01082457_.py +++ b/migrations/versions/7bbc01082457_.py @@ -255,17 +255,9 @@ def upgrade(): if mapped_org not in orgs_inserted: org_managers[mapped_org] = org_manager - conn.execute( - sa.text( - "insert into organisation_managers \ + conn.execute(sa.text("insert into organisation_managers \ (organisation_id,user_id) \ - values(" - + org_id - + "," - + org_manager - + ")" - ) - ) + values(" + org_id + "," + org_manager + ")")) print( str(count) + "/" diff --git a/migrations/versions/909c5b13b1fc_.py b/migrations/versions/909c5b13b1fc_.py index d663aae33f..969e2f8ceb 100644 --- a/migrations/versions/909c5b13b1fc_.py +++ b/migrations/versions/909c5b13b1fc_.py @@ -17,36 +17,28 @@ def upgrade(): conn = op.get_bind() - cur = conn.execute( - sa.text( - """ + cur = conn.execute(sa.text(""" INSERT INTO mapping_badges (name, description, requirements, is_enabled, is_internal) VALUES ('INTERMEDIATE_internal', '', '{\"changeset\": 250}', true, true), ('ADVANCED_internal', '', '{\"changeset\": 500}', true, true) RETURNING id - """ - ) - ) + """)) ids = [r[0] for r in cur.fetchall()] conn.execute( - sa.text( - """ + sa.text(""" INSERT INTO mapping_level_badges (level_id, badge_id) VALUES (:level_id, :badge_id) - """ - ), + """), {"level_id": 2, "badge_id": ids[0]}, ) conn.execute( - sa.text( - """ + sa.text(""" INSERT INTO mapping_level_badges (level_id, badge_id) VALUES (:level_id, :badge_id) - """ - ), + """), {"level_id": 3, "badge_id": ids[1]}, ) diff --git a/migrations/versions/b720f42ce3e8_.py b/migrations/versions/b720f42ce3e8_.py index ecfea74d14..07e087dbda 100644 --- a/migrations/versions/b720f42ce3e8_.py +++ b/migrations/versions/b720f42ce3e8_.py @@ -9,7 +9,6 @@ from alembic import op import sqlalchemy as sa - # revision identifiers, used by Alembic. revision = "b720f42ce3e8" down_revision = "763165f937cf" diff --git a/scripts/commands/refresh_mapper_level.py b/scripts/commands/refresh_mapper_level.py index 7b24624c6e..b3b6abab4b 100644 --- a/scripts/commands/refresh_mapper_level.py +++ b/scripts/commands/refresh_mapper_level.py @@ -113,16 +113,14 @@ async def _fetch_users_only_missing(conn) -> List[SimpleNamespace]: """ Return lightweight objects (id, username) for users missing user_stats entries. """ - users = await conn.fetch_all( - query=""" + users = await conn.fetch_all(query=""" SELECT u.id, u.username FROM users u WHERE NOT EXISTS ( SELECT 1 FROM user_stats s WHERE s.user_id = u.id ) ORDER BY u.id - """ - ) + """) return users diff --git a/tests/api/helpers/test_helpers.py b/tests/api/helpers/test_helpers.py index ab9ec890ff..1fb8aaf250 100644 --- a/tests/api/helpers/test_helpers.py +++ b/tests/api/helpers/test_helpers.py @@ -63,32 +63,20 @@ async def create_mapping_levels(db): # Ensure clean slate (important for repeated test runs) await db.execute(sa.text("DELETE FROM mapping_levels")) - await db.execute( - sa.text( - """ + await db.execute(sa.text(""" INSERT INTO mapping_levels (id, name, ordering, is_beginner, approvals_required) VALUES (1, 'BEGINNER', 1, true, 0) - """ - ) - ) + """)) - await db.execute( - sa.text( - """ + await db.execute(sa.text(""" INSERT INTO mapping_levels (id, name, ordering, is_beginner, approvals_required) VALUES (2, 'INTERMEDIATE', 2, false, 0) - """ - ) - ) + """)) - await db.execute( - sa.text( - """ + await db.execute(sa.text(""" INSERT INTO mapping_levels (id, name, ordering, is_beginner, approvals_required) VALUES (3, 'ADVANCED', 3, false, 0) - """ - ) - ) + """)) def get_canned_osm_user_details(): diff --git a/tests/api/integration/services/users/test_authentication_service.py b/tests/api/integration/services/users/test_authentication_service.py index 62244db1c7..c18b7715ff 100644 --- a/tests/api/integration/services/users/test_authentication_service.py +++ b/tests/api/integration/services/users/test_authentication_service.py @@ -22,7 +22,6 @@ TEST_USERNAME, ) - TEST_USER_EMAIL = "thinkwheretest@test.com" diff --git a/tests/api/unit/services/messaging/test_messaging_service.py b/tests/api/unit/services/messaging/test_messaging_service.py index 14572e74b5..539a0c8b10 100644 --- a/tests/api/unit/services/messaging/test_messaging_service.py +++ b/tests/api/unit/services/messaging/test_messaging_service.py @@ -4,7 +4,6 @@ from backend.models.postgis.message import Message from backend.services.messaging.message_service import MessageService - MESSAGE_TYPES = "3,2,1" TEST_USER_ID = 111111111