Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ def storage_service_store(path, file_path, *, meta):
# Ensure that all of our journal entries have been created
journals = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.order_by("submitted_date", "id")
.all()
)
Expand Down Expand Up @@ -2110,7 +2110,7 @@ def test_upload_succeeds_custom_project_size_limit(
# Ensure that all of our journal entries have been created
journals = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.order_by("submitted_date", "id")
.all()
)
Expand Down Expand Up @@ -2745,7 +2745,7 @@ def storage_service_store(path, file_path, *, meta):
# Ensure that all of our journal entries have been created
journals = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.order_by("submitted_date", "id")
.all()
)
Expand Down Expand Up @@ -2875,7 +2875,7 @@ def storage_service_store(path, file_path, *, meta):
# Ensure that all of our journal entries have been created
journals = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.order_by("submitted_date", "id")
.all()
)
Expand Down Expand Up @@ -3136,7 +3136,7 @@ def test_upload_succeeds_creates_release(
# Ensure that all of our journal entries have been created
journals = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.order_by("submitted_date", "id")
.all()
)
Expand Down Expand Up @@ -3428,7 +3428,7 @@ def test_upload_succeeds_creates_project(
# Ensure that all of our journal entries have been created
journals = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.order_by("submitted_date", "id")
.all()
)
Expand Down
26 changes: 19 additions & 7 deletions tests/unit/manage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def test_delete_account(self, monkeypatch, db_request):

journal = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.filter_by(id=jid)
.one()
)
Expand Down Expand Up @@ -3969,7 +3969,9 @@ def test_yank_project_release(self, monkeypatch, db_request):
)
]
entry = (
db_request.db.query(JournalEntry).options(joinedload("submitted_by")).one()
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)
assert entry.name == release.project.name
assert entry.action == "yank release"
Expand Down Expand Up @@ -4122,7 +4124,9 @@ def test_unyank_project_release(self, monkeypatch, db_request):
]

entry = (
db_request.db.query(JournalEntry).options(joinedload("submitted_by")).one()
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)
assert entry.name == release.project.name
assert entry.action == "unyank release"
Expand Down Expand Up @@ -4279,7 +4283,9 @@ def test_delete_project_release(self, monkeypatch, db_request):

assert db_request.db.query(Release).all() == []
entry = (
db_request.db.query(JournalEntry).options(joinedload("submitted_by")).one()
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)
assert entry.name == release.project.name
assert entry.action == "remove release"
Expand Down Expand Up @@ -5450,7 +5456,9 @@ def test_change_role(self, db_request, monkeypatch):
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry).options(joinedload("submitted_by")).one()
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == project.name
Expand Down Expand Up @@ -5567,7 +5575,9 @@ def test_delete_role(self, db_request, monkeypatch):
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry).options(joinedload("submitted_by")).one()
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == project.name
Expand Down Expand Up @@ -5662,7 +5672,9 @@ def test_delete_not_sole_owner_role(self, db_request, monkeypatch):
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry).options(joinedload("submitted_by")).one()
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == project.name
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/manage/views/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,9 @@ def test_change_role(
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry).options(joinedload("submitted_by")).one()
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == organization_project.name
Expand Down Expand Up @@ -1016,7 +1018,9 @@ def test_delete_role(
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry).options(joinedload("submitted_by")).one()
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == organization_project.name
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_remove_project(db_request, flash):

journal_entry = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.filter(JournalEntry.name == "foo")
.one()
)
Expand All @@ -157,7 +157,7 @@ def test_destroy_docs(db_request, flash):

journal_entry = (
db_request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.filter(JournalEntry.name == "foo")
.one()
)
Expand Down
3 changes: 1 addition & 2 deletions warehouse/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class User(SitemapMixin, HasEvents, db.Model):

macaroons = orm.relationship(
"Macaroon",
backref="user",
cascade="all, delete-orphan",
lazy=True,
order_by="Macaroon.created.desc()",
Expand Down Expand Up @@ -141,7 +140,7 @@ def email(self):
@email.expression # type: ignore
def email(self):
return (
select([Email.email])
select(Email.email)
.where((Email.user_id == self.id) & (Email.primary.is_(True)))
.scalar_subquery()
)
Expand Down
6 changes: 3 additions & 3 deletions warehouse/admin/views/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def project_detail(project, request):
entry
for entry in (
request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.filter(JournalEntry.name == project.name)
.order_by(JournalEntry.submitted_date.desc(), JournalEntry.id.desc())
.limit(30)
Expand Down Expand Up @@ -198,7 +198,7 @@ def releases_list(project, request):
def release_detail(release, request):
journals = (
request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.filter(JournalEntry.name == release.project.name)
.filter(JournalEntry.version == release.version)
.order_by(JournalEntry.submitted_date.desc(), JournalEntry.id.desc())
Expand Down Expand Up @@ -230,7 +230,7 @@ def journals_list(project, request):

journals_query = (
request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.filter(JournalEntry.name == project.name)
.order_by(JournalEntry.submitted_date.desc(), JournalEntry.id.desc())
)
Expand Down
2 changes: 1 addition & 1 deletion warehouse/admin/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def _nuke_user(user, request):

journals = (
request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.filter(JournalEntry.submitted_by == user)
.all()
)
Expand Down
5 changes: 4 additions & 1 deletion warehouse/legacy/api/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def _json_data(request, project, release, *, all_releases):
request.db.query(Release, File)
.options(
Load(Release).load_only(
"version", "requires_python", "yanked", "yanked_reason"
Release.version,
Release.requires_python,
Release.yanked,
Release.yanked_reason,
)
)
.outerjoin(File)
Expand Down
11 changes: 7 additions & 4 deletions warehouse/legacy/api/xmlrpc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def package_hosting_mode(request, package_name: str):
def user_packages(request, username: str):
roles = (
request.db.query(Role)
.join(User, Project)
.join(User)
.join(Project)
.filter(User.username == username)
.order_by(Role.role_name.desc(), Project.name)
.all()
Expand Down Expand Up @@ -385,7 +386,8 @@ def package_urls(request, package_name, version):
def release_urls(request, package_name: str, version: str):
files = (
request.db.query(File)
.join(Release, Project)
.join(Release)
.join(Project)
.filter(
(Project.normalized_name == func.normalize_pep426_name(package_name))
& (Release.version == version)
Expand Down Expand Up @@ -422,7 +424,8 @@ def release_urls(request, package_name: str, version: str):
def package_roles(request, package_name: str):
roles = (
request.db.query(Role)
.join(User, Project)
.join(User)
.join(Project)
.filter(Project.normalized_name == func.normalize_pep426_name(package_name))
.order_by(Role.role_name.desc(), User.username)
.all()
Expand Down Expand Up @@ -492,7 +495,7 @@ def browse(request, classifiers: list[str]):
)

release_classifiers_q = (
select([release_classifiers])
select(release_classifiers)
.where(release_classifiers.c.trove_id == classifiers_q.c.id)
.alias("rc")
)
Expand Down
6 changes: 6 additions & 0 deletions warehouse/macaroons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
LargeBinary,
String,
UniqueConstraint,
orm,
sql,
)
from sqlalchemy.dialects.postgresql import JSONB, UUID
Expand Down Expand Up @@ -76,3 +77,8 @@ class Macaroon(db.Model):
# prefer to just always use urandom. Thus we'll do this ourselves here
# in our application.
key = Column(LargeBinary, nullable=False, default=_generate_key)

# Intentionally not using a back references here, since we express
# relationships in terms of the "other" side of the relationship.
user = orm.relationship("User", lazy=True, viewonly=True)
oidc_publisher = orm.relationship("OIDCPublisher", lazy=True, viewonly=True)
4 changes: 3 additions & 1 deletion warehouse/macaroons/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def find_macaroon(self, macaroon_id):
return None

return self.db.get(
Macaroon, macaroon_id, (joinedload("user"), joinedload("oidc_publisher"))
Macaroon,
macaroon_id,
(joinedload(Macaroon.user), joinedload(Macaroon.oidc_publisher)),
)

def _deserialize_raw_macaroon(self, raw_macaroon):
Expand Down
4 changes: 2 additions & 2 deletions warehouse/manage/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def delete_account(self):

journals = (
self.request.db.query(JournalEntry)
.options(joinedload("submitted_by"))
.options(joinedload(JournalEntry.submitted_by))
.filter(JournalEntry.submitted_by == self.request.user)
.all()
)
Expand Down Expand Up @@ -1553,7 +1553,7 @@ def manage_project_releases(project, request):
# release version and the package types
filecounts = (
request.db.query(Release.version, File.packagetype, func.count(File.id))
.options(Load(Release).load_only("version"))
.options(Load(Release).load_only(Release.version))
.outerjoin(File)
.group_by(Release.id)
.group_by(File.packagetype)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

def upgrade():
connection = op.get_bind()
version_query = sa.select([releases.c.version]).distinct()
version_query = sa.select(releases.c.version).distinct()

for release in connection.execute(version_query):
connection.execute(
Expand Down
4 changes: 1 addition & 3 deletions warehouse/oidc/models/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ class OIDCPublisher(OIDCPublisherMixin, db.Model):
secondary=OIDCPublisherProjectAssociation.__table__, # type: ignore
backref="oidc_publishers",
)
macaroons = orm.relationship(
Macaroon, backref="oidc_publisher", cascade="all, delete-orphan", lazy=True
)
macaroons = orm.relationship(Macaroon, cascade="all, delete-orphan", lazy=True)

__mapper_args__ = {
"polymorphic_identity": "oidc_publishers",
Expand Down
2 changes: 1 addition & 1 deletion warehouse/organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def __acl__(self):
query = session.query(OrganizationRole).filter(
OrganizationRole.organization == self
)
query = query.options(orm.lazyload("organization"))
query = query.options(orm.lazyload(OrganizationRole.organization))
query = query.join(User).order_by(User.id.asc())
for role in sorted(
query.all(),
Expand Down
12 changes: 6 additions & 6 deletions warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ def __acl__(self):

# Get all of the users for this project.
query = session.query(Role).filter(Role.project == self)
query = query.options(orm.lazyload("project"))
query = query.options(orm.lazyload("user"))
query = query.options(orm.lazyload(Role.project))
query = query.options(orm.lazyload(Role.user))
permissions = {
(role.user_id, "Administer" if role.role_name == "Owner" else "Upload")
for role in query.all()
}

# Add all of the team members for this project.
query = session.query(TeamProjectRole).filter(TeamProjectRole.project == self)
query = query.options(orm.lazyload("project"))
query = query.options(orm.lazyload("team"))
query = query.options(orm.lazyload(TeamProjectRole.project))
query = query.options(orm.lazyload(TeamProjectRole.team))
for role in query.all():
permissions |= {
(user.id, "Administer" if role.role_name.value == "Owner" else "Upload")
Expand All @@ -287,8 +287,8 @@ def __acl__(self):
OrganizationRole.organization == self.organization,
OrganizationRole.role_name == OrganizationRoleType.Owner,
)
query = query.options(orm.lazyload("organization"))
query = query.options(orm.lazyload("user"))
query = query.options(orm.lazyload(OrganizationRole.organization))
query = query.options(orm.lazyload(OrganizationRole.user))
permissions |= {(role.user_id, "Administer") for role in query.all()}

for user_id, permission_name in sorted(permissions, key=lambda x: (x[1], x[0])):
Expand Down
2 changes: 1 addition & 1 deletion warehouse/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def search(request):
request.db.query(Classifier)
.with_entities(Classifier.classifier)
.filter(
exists([release_classifiers.c.trove_id]).where(
exists(release_classifiers.c.trove_id).where(
release_classifiers.c.trove_id == Classifier.id
),
Classifier.classifier.notin_(deprecated_classifiers.keys()),
Expand Down