Skip to content

Commit da18ce6

Browse files
Merge pull request #156 from ComplexData-MILA/test-push
Test push
2 parents ef1533f + 1bd0bb2 commit da18ce6

5 files changed

Lines changed: 47 additions & 20 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ repos:
33
rev: 22.10.0
44
hooks:
55
- id: black
6+
language_version: python3.12
67
- repo: https://github.com/PyCQA/flake8
78
rev: 7.1.1
89
hooks:

app/repositories/implementations/analysis_repository.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ async def create(self, analysis: Analysis) -> Analysis:
3434

3535
return self._to_domain(model)
3636

37+
async def update_stream_safe(self, analysis: Analysis) -> Analysis:
38+
"""Update with proper async handling."""
39+
db_obj = self._to_model(analysis)
40+
merged_obj = await self._session.merge(db_obj)
41+
await self._session.commit()
42+
self._session.expunge(merged_obj)
43+
44+
return analysis
45+
3746
async def get_with_relations(self, analysis_id: UUID) -> Optional[Analysis]:
3847
"""Get analysis with related sources and feedback."""
3948
query = (

app/services/analysis_orchestrator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ async def _generate_analysis(
264264
log_data = LogProbsData(tokens=analysis_text, probs=log_probs)
265265
current_analysis.log_probs = log_data
266266

267-
updated_analysis = await self._analysis_repo.update(current_analysis)
267+
updated_analysis = await self._analysis_repo.update_stream_safe(current_analysis)
268268

269269
yield {
270270
"type": "analysis_complete",

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
depends_on:
1515
misinformation_mitigation_db:
1616
condition: service_healthy
17-
command: [ "/app/docker-entrypoint.sh" ]
17+
command: ["sh","/app/docker-entrypoint.sh" ]
1818

1919
misinformation_mitigation_db:
2020
container_name: misinformation_mitigation_db

migrations/versions/2abb9260c6fd_add_batch_user_id_to_claims_table.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Revision ID: 2abb9260c6fd
44
Revises: b2122b621d0a
55
Create Date: 2025-04-10 21:03:31.820890
6-
76
"""
7+
88
from typing import Sequence, Union
99

10-
from alembic import op
1110
import sqlalchemy as sa
11+
from alembic import op
1212

1313
# revision identifiers, used by Alembic.
1414
revision: str = "2abb9260c6fd"
@@ -18,48 +18,65 @@
1818

1919

2020
def upgrade() -> None:
21-
# ### commands auto generated by Alembic - please adjust! ###
21+
# Existing migration: add the new column
2222
op.add_column("claims", sa.Column("batch_user_id", sa.Text(), nullable=True))
23-
# ### end Alembic commands ###
2423

24+
# Existing migration: create the new table
2525
op.execute(
2626
"""
2727
CREATE TABLE social_media_clients (
28-
auth0_id VARCHAR PRIMARY KEY REFERENCES users(auth0_id),
29-
platform TEXT NOT NULL
28+
auth0_id VARCHAR PRIMARY KEY REFERENCES users(auth0_id),
29+
platform TEXT NOT NULL
3030
);
31-
"""
31+
"""
3232
)
3333

34+
# The change makes the migration safe by preventing inserts into social_media_clients unless the referenced user already exists in users.
35+
36+
# New: only insert BlueSky client if the matching user already exists
3437
op.execute(
3538
"""
3639
INSERT INTO social_media_clients (auth0_id, platform)
37-
VALUES ('I1eyLfAX26wlOMiY4n5SxWOsWrSNXLWU@clients', 'BlueSky');
38-
"""
40+
SELECT 'I1eyLfAX26wlOMiY4n5SxWOsWrSNXLWU@clients', 'BlueSky'
41+
WHERE EXISTS (
42+
SELECT 1 FROM users
43+
WHERE auth0_id = 'I1eyLfAX26wlOMiY4n5SxWOsWrSNXLWU@clients'
44+
);
45+
"""
3946
)
4047

48+
# New: only insert X client if the matching user already exists
4149
op.execute(
4250
"""
4351
INSERT INTO social_media_clients (auth0_id, platform)
44-
VALUES ('K46Fnu6E21BG0x3KfNknffbKdTbOHlzw@clients', 'X');
45-
"""
52+
SELECT 'K46Fnu6E21BG0x3KfNknffbKdTbOHlzw@clients', 'X'
53+
WHERE EXISTS (
54+
SELECT 1 FROM users
55+
WHERE auth0_id = 'K46Fnu6E21BG0x3KfNknffbKdTbOHlzw@clients'
56+
);
57+
"""
4658
)
4759

60+
# New: only insert Reddit client if the matching user already exists
4861
op.execute(
4962
"""
5063
INSERT INTO social_media_clients (auth0_id, platform)
51-
VALUES ('GbaexhSrWJnbX19M4HYuGH87ROyzwJne@clients', 'Reddit');
52-
"""
64+
SELECT 'GbaexhSrWJnbX19M4HYuGH87ROyzwJne@clients', 'Reddit'
65+
WHERE EXISTS (
66+
SELECT 1 FROM users
67+
WHERE auth0_id = 'GbaexhSrWJnbX19M4HYuGH87ROyzwJne@clients'
68+
);
69+
"""
5370
)
5471

5572

5673
def downgrade() -> None:
57-
# ### commands auto generated by Alembic - please adjust! ###
58-
op.drop_column("claims", "batch_user_id")
59-
# ### end Alembic commands ###
60-
74+
# Existing migration: drop the social_media_clients table
6175
op.execute(
6276
"""
6377
DROP TABLE social_media_clients;
64-
"""
78+
"""
6579
)
80+
81+
# Existing migration: remove the batch_user_id column
82+
op.drop_column("claims", "batch_user_id")

0 commit comments

Comments
 (0)