Issue #6147
closedRepository.latest_version() doesn't take into account deleted repository versions
Description
The serializer does the correct thing, because the serializer does not use Repository.latest_version()
(pulp) [vagrant@pulp3-source-fedora31 pulp_rpm]$ http :24817${TARGET_REPO}versions/
HTTP/1.1 200 OK
Allow: GET, HEAD, OPTIONS
Connection: close
Content-Length: 283
Content-Type: application/json
Date: Wed, 12 Feb 2020 18:40:06 GMT
Server: gunicorn/20.0.4
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"base_version": null,
"content_summary": {
"added": {},
"present": {},
"removed": {}
},
"number": 0,
"pulp_created": "2020-02-11T21:52:54.154568Z",
"pulp_href": "/pulp/api/v3/repositories/rpm/rpm/8df090fe-a51e-4d23-acc4-e140e6294e02/versions/0/"
}
]
}
(pulp) [vagrant@pulp3-source-fedora31 pulp_rpm]$ http :24817${TARGET_REPO}
HTTP/1.1 200 OK
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Connection: close
Content-Length: 377
Content-Type: application/json
Date: Wed, 12 Feb 2020 18:40:17 GMT
Server: gunicorn/20.0.4
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
{
"description": null,
"latest_version_href": "/pulp/api/v3/repositories/rpm/rpm/8df090fe-a51e-4d23-acc4-e140e6294e02/versions/0/",
"name": "targetrepo",
"pulp_created": "2020-02-11T21:52:54.152669Z",
"pulp_href": "/pulp/api/v3/repositories/rpm/rpm/8df090fe-a51e-4d23-acc4-e140e6294e02/",
"versions_href": "/pulp/api/v3/repositories/rpm/rpm/8df090fe-a51e-4d23-acc4-e140e6294e02/versions/"
}
However, underneath the hood, Pulp and plugin writers might have a problem, because if the "latest version" was deleted, Repository.latest_version() will return "None" instead of the one prior to the deleted one.
In [1]: RpmRepository.objects.all()[1].latest_version()
In [2]: RepositoryVersion.objects.filter(repository=RpmRepository.objects.all()[1])
Out[2]: <QuerySet [<Repository: targetrepo; Version: 0>]>
In [3]: RpmRepository.objects.all()[1].last_version
Out[3]: 1
So what the JSON API returns and what the internal APIs return do not match up.
Anything that uses the internal APIs to find the latest version, like copy (what I'm working on) or probably distributions (though I haven't tested it) will run into this issue.
Updated by daviddavis almost 5 years ago
+1 we need to fix this. Think it would be nice to add a unit test here too.
Updated by fao89 almost 5 years ago
- Triaged changed from No to Yes
- Sprint set to Sprint 66
Updated by fao89 almost 5 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to fao89
Updated by fao89 almost 5 years ago
- Status changed from ASSIGNED to POST
Added by Fabricio Aguiar almost 5 years ago
Updated by Anonymous almost 5 years ago
- Status changed from POST to MODIFIED
Applied in changeset pulpcore|d038c1fbb2d84466cfb1c6a2ad5b7733914d0fb8.
Added by Fabricio Aguiar almost 5 years ago
Revision aa22d82a | View on GitHub
Rename last_version
https://pulp.plan.io/issues/6147 Required PR: https://github.com/pulp/pulpcore/pull/555 ref #6147
Added by daviddavis almost 5 years ago
Revision f20b95f3 | View on GitHub
Update changelog message and make it misc since it doesn't impact users
ref #6147
Updated by daviddavis almost 5 years ago
- Status changed from MODIFIED to CLOSED - CURRENTRELEASE
Deleted versions update Repository.last_version
https://pulp.plan.io/issues/6147 closes #6147