Skip to content

Commit c1f91c9

Browse files
committed
tests: comment out data migration
The migration ran in production in April. Using ORM objects in migrations is apparently dangerous for tests, since we run the entire migration stack from scratch, and **later** modifications to a model are not available at the point this migration is being executed. Signed-off-by: Mike Fiedler <[email protected]>
1 parent 1881911 commit c1f91c9

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

warehouse/migrations/versions/c978a4eaa0f6_add_observation_related_name.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from alembic import op
2323

24-
from warehouse.packaging.models import Project
24+
# from warehouse.packaging.models import Project
2525

2626
revision = "c978a4eaa0f6"
2727
down_revision = "56b3ef8e8af3"
@@ -60,17 +60,20 @@ def upgrade():
6060
),
6161
)
6262

63+
# NOTE: Commenting out the following to avoid failing other migrations during tests.
64+
# Migration ran successfully in production on 2024-04-17
65+
6366
# Data migration to set the related_name for existing rows.
64-
bind = op.get_bind()
65-
session = sa.orm.Session(bind=bind)
66-
# Get all Projects with Observations
67-
projects_query = sa.select(Project).where(Project.observations.any())
68-
# For each, set the `related_name` to the related Project's model name
69-
for project in session.scalars(projects_query):
70-
for observation in project.observations:
71-
observation.related_name = repr(project)
72-
session.add(observation)
73-
session.commit()
67+
# bind = op.get_bind()
68+
# session = sa.orm.Session(bind=bind)
69+
# # Get all Projects with Observations
70+
# projects_query = sa.select(Project).where(Project.observations.any())
71+
# # For each, set the `related_name` to the related Project's model name
72+
# for project in session.scalars(projects_query):
73+
# for observation in project.observations:
74+
# observation.related_name = repr(project)
75+
# session.add(observation)
76+
# session.commit()
7477

7578
# Flip the nullable flag to False
7679
op.alter_column("project_observations", "related_name", nullable=False)

0 commit comments

Comments
 (0)