Skip to content

deterministicly order journal entrys by id #3475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2018
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
14 changes: 7 additions & 7 deletions tests/unit/admin/views/test_journals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestProjectList:
def test_no_query(self, db_request):
journals = sorted(
[JournalEntryFactory.create() for _ in range(30)],
key=lambda j: j.submitted_date,
key=lambda j: (j.submitted_date, j.id),
reverse=True,
)
result = views.journals_list(db_request)
Expand All @@ -42,7 +42,7 @@ def test_no_query(self, db_request):
def test_with_page(self, db_request):
journals = sorted(
[JournalEntryFactory.create() for _ in range(30)],
key=lambda j: j.submitted_date,
key=lambda j: (j.submitted_date, j.id),
reverse=True,
)
db_request.GET["page"] = "2"
Expand All @@ -65,7 +65,7 @@ def test_query_basic(self, db_request):
journals0 = sorted(
[JournalEntryFactory.create(name=project0.normalized_name)
for _ in range(30)],
key=lambda j: j.submitted_date,
key=lambda j: (j.submitted_date, j.id),
reverse=True,
)
[JournalEntryFactory.create(name=project1.normalized_name)
Expand All @@ -85,7 +85,7 @@ def test_query_term_project(self, db_request):
journals0 = sorted(
[JournalEntryFactory.create(name=project0.normalized_name)
for _ in range(30)],
key=lambda j: j.submitted_date,
key=lambda j: (j.submitted_date, j.id),
reverse=True,
)
[JournalEntryFactory.create(name=project1.normalized_name)
Expand All @@ -105,7 +105,7 @@ def test_query_term_user(self, db_request):
journals0 = sorted(
[JournalEntryFactory.create(submitted_by=user0)
for _ in range(30)],
key=lambda j: j.submitted_date,
key=lambda j: (j.submitted_date, j.id),
reverse=True,
)
[JournalEntryFactory.create(submitted_by=user1)
Expand Down Expand Up @@ -139,13 +139,13 @@ def test_query_term_ip(self, db_request):
journals0 = sorted(
[JournalEntryFactory.create(submitted_from=ipv4)
for _ in range(10)],
key=lambda j: j.submitted_date,
key=lambda j: (j.submitted_date, j.id),
reverse=True,
)
journals1 = sorted(
[JournalEntryFactory.create(submitted_from=ipv6)
for _ in range(10)],
key=lambda j: j.submitted_date,
key=lambda j: (j.submitted_date, j.id),
reverse=True,
)

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/admin/views/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_gets_project(self, db_request):
journals = sorted(
[JournalEntryFactory(name=project.name)
for _ in range(75)],
key=lambda x: x.submitted_date,
key=lambda x: (x.submitted_date, x.id),
reverse=True,
)
roles = sorted(
Expand Down Expand Up @@ -257,7 +257,7 @@ def test_no_query(self, db_request):
journals = sorted(
[JournalEntryFactory(name=project.name)
for _ in range(30)],
key=lambda x: x.submitted_date,
key=lambda x: (x.submitted_date, x.id),
reverse=True,
)
db_request.matchdict["project_name"] = project.normalized_name
Expand All @@ -274,7 +274,7 @@ def test_with_page(self, db_request):
journals = sorted(
[JournalEntryFactory(name=project.name)
for _ in range(30)],
key=lambda x: x.submitted_date,
key=lambda x: (x.submitted_date, x.id),
reverse=True,
)
db_request.matchdict["project_name"] = project.normalized_name
Expand All @@ -300,7 +300,7 @@ def test_version_query(self, db_request):
journals = sorted(
[JournalEntryFactory(name=project.name)
for _ in range(30)],
key=lambda x: x.submitted_date,
key=lambda x: (x.submitted_date, x.id),
reverse=True,
)
db_request.matchdict["project_name"] = project.normalized_name
Expand All @@ -318,7 +318,7 @@ def test_invalid_key_query(self, db_request):
journals = sorted(
[JournalEntryFactory(name=project.name)
for _ in range(30)],
key=lambda x: x.submitted_date,
key=lambda x: (x.submitted_date, x.id),
reverse=True,
)
db_request.matchdict["project_name"] = project.normalized_name
Expand All @@ -336,7 +336,7 @@ def test_basic_query(self, db_request):
journals = sorted(
[JournalEntryFactory(name=project.name)
for _ in range(30)],
key=lambda x: x.submitted_date,
key=lambda x: (x.submitted_date, x.id),
reverse=True,
)
db_request.matchdict["project_name"] = project.normalized_name
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,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)
.order_by("submitted_date")
.order_by("submitted_date", "id")
.all()
)
assert [
Expand Down Expand Up @@ -2160,7 +2160,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)
.order_by("submitted_date")
.order_by("submitted_date", "id")
.all()
)
assert [
Expand Down Expand Up @@ -2270,7 +2270,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)
.order_by("submitted_date")
.order_by("submitted_date", "id")
.all()
)
assert [
Expand Down Expand Up @@ -2506,7 +2506,7 @@ def test_upload_succeeds_creates_release(self, pyramid_config, db_request):
# Ensure that all of our journal entries have been created
journals = (
db_request.db.query(JournalEntry)
.order_by("submitted_date")
.order_by("submitted_date", "id")
.all()
)
assert [
Expand Down Expand Up @@ -2679,7 +2679,7 @@ def test_upload_succeeds_creates_project(self, pyramid_config, db_request):
# Ensure that all of our journal entries have been created
journals = (
db_request.db.query(JournalEntry)
.order_by("submitted_date")
.order_by("submitted_date", "id")
.all()
)
assert [
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/legacy/api/xmlrpc/test_xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def test_changelog(db_request, with_ids):
for _ in range(10):
entries.append(JournalEntryFactory.create(name=project.name))

entries = sorted(entries, key=lambda x: x.submitted_date)
entries = sorted(entries, key=lambda x: x.id)

since = int(
entries[int(len(entries) / 2)].submitted_date
Expand Down
4 changes: 3 additions & 1 deletion warehouse/admin/views/journals.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def journals_list(request):

journals_query = (
request.db.query(JournalEntry)
.order_by(JournalEntry.submitted_date.desc())
.order_by(
JournalEntry.submitted_date.desc(),
JournalEntry.id.desc())
)

if q:
Expand Down
9 changes: 7 additions & 2 deletions warehouse/admin/views/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ def project_detail(project, request):
for entry in (
request.db.query(JournalEntry)
.filter(JournalEntry.name == project.name)
.order_by(JournalEntry.submitted_date.desc())
.order_by(
JournalEntry.submitted_date.desc(),
JournalEntry.id.desc(),
)
.limit(30)
)
]
Expand Down Expand Up @@ -208,7 +211,9 @@ def journals_list(project, request):

journals_query = (request.db.query(JournalEntry)
.filter(JournalEntry.name == project.name)
.order_by(JournalEntry.submitted_date.desc()))
.order_by(
JournalEntry.submitted_date.desc(),
JournalEntry.id.desc()))

if q:
terms = shlex.split(q)
Expand Down
2 changes: 1 addition & 1 deletion warehouse/legacy/api/xmlrpc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def changelog(request, since, with_ids=False):
entries = (
request.db.query(JournalEntry)
.filter(JournalEntry.submitted_date > since)
.order_by(JournalEntry.submitted_date)
.order_by(JournalEntry.id)
.limit(50000)
)

Expand Down
2 changes: 1 addition & 1 deletion warehouse/manage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def manage_project_history(project, request):
journals = (
request.db.query(JournalEntry)
.filter(JournalEntry.name == project.name)
.order_by(JournalEntry.submitted_date.desc())
.order_by(JournalEntry.submitted_date.desc(), JournalEntry.id.desc())
.all()
)
return {
Expand Down
2 changes: 1 addition & 1 deletion warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def __table_args__(cls): # noqa
secondaryjoin=lambda: (
(User.username == orm.foreign(JournalEntry._submitted_by))
),
order_by=lambda: JournalEntry.submitted_date.desc(),
order_by=lambda: JournalEntry.id.desc(),
# TODO: We have uselist=False here which raises a warning because
# multiple items were returned. This should only be temporary because
# we should add a nullable FK to JournalEntry so we don't need to rely
Expand Down