Closed chriz-uniba closed 2 years ago
First step to figure out what's going wrong:
>>> rdm.draft.create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/chriz/rz/code/invenio/repos/iridium/iridium/iridium/inveniordm/__init__.py", line 467, in create
return Record.parse_obj(r.json())
File "/home/chriz/rz/code/invenio/repos/iridium/iridium/iridium/inveniordm/models/base.py", line 66, in parse_obj
return cast(cls, super().parse_obj(val, *args, **kwargs))
File "pydantic/main.py", line 578, in pydantic.main.BaseModel.parse_obj
File "/home/chriz/rz/code/invenio/repos/iridium/iridium/iridium/inveniordm/models/base.py", line 29, in __init__
super().__init__(*args, **kwargs)
File "pydantic/main.py", line 406, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Record
is_draft
extra fields not permitted (type=value_error.extra)
>>>
While the bash-command seems to be happy:
curl --oauth2-bearer $TOKEN -H "Content-Type: application/json" -X POST --data @$DATA $URL/api/records | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1378 100 1378 0 0 3870 0 --:--:-- --:--:-- --:--:-- 3870
Using a valid 'URL' and 'TOKEN' and having DATA=empty.json
with the empty file empty.json
.
Status update:
The return value of creating an empty draft is something like this:
{
"is_published": false,
"links": {
"self": "https://127.0.0.1/api/records/cf0gn-v0c04/draft",
"self_html": "https://127.0.0.1/uploads/cf0gn-v0c04",
"files": "https://127.0.0.1/api/records/cf0gn-v0c04/draft/files",
"record": "https://127.0.0.1/api/records/cf0gn-v0c04",
"record_html": "https://127.0.0.1/records/cf0gn-v0c04",
"publish": "https://127.0.0.1/api/records/cf0gn-v0c04/draft/actions/publish",
"review": "https://127.0.0.1/api/records/cf0gn-v0c04/draft/review",
"versions": "https://127.0.0.1/api/records/cf0gn-v0c04/versions",
"access_links": "https://127.0.0.1/api/records/cf0gn-v0c04/access/links",
"reserve_doi": "https://127.0.0.1/api/records/cf0gn-v0c04/draft/pids/doi"
},
"created": "2022-03-08T14:20:08.408703+00:00",
"is_draft": true,
"parent": {
"communities": {},
"access": {
"owned_by": [
{
"user": 3
}
],
"links": []
},
"id": "zbazq-rwf72"
},
"pids": {},
"updated": "2022-03-08T14:20:08.433255+00:00",
"versions": {
"is_latest": false,
"is_latest_draft": true,
"index": 1
},
"metadata": {},
"expires_at": "2022-03-08 14:20:08.408762",
"files": {
"order": [],
"enabled": true
},
"access": {
"status": "metadata-only",
"files": "public",
"record": "public",
"embargo": {
"reason": null,
"active": false
}
},
"revision_id": 3,
"id": "cf0gn-v0c04"
}
with respect to v7 there is a new field "is_draft": true,
.
@apirogov commented on this elsewhere:
Adding in technical.py
next to is_published
a field is_draft: bool
could do the trick.
Indeed this fixes some tests. Still 3 are failing.
After adding the field is_draft
the following three tests are failing:
$ poetry run pytest
================================================================== test session starts ==================================================================
platform linux -- Python 3.9.2, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/chriz/rz/code/invenio/repos/iridium/iridium, configfile: pyproject.toml
plugins: anyio-3.5.0, cov-3.0.0, dotenv-0.5.2
collected 14 items
tests/test_api.py .FF [ 21%]
tests/test_generic.py ... [ 42%]
tests/test_inveniordm_api.py .F.... [ 85%]
tests/test_utils.py .. [100%]
======================================================================= FAILURES ========================================================================
______________________________________________________________ test_readonly_fields_draft _______________________________________________________________
irdm = <iridium.api.Repository object at 0x7f083720ec00>
def test_readonly_fields_draft(irdm):
draft = irdm.drafts.create()
assert isinstance(draft, WrappedRecord)
# should not be able to add new things
with pytest.raises(ValueError):
draft.something = "value"
# should not be able to modify certain public things...
# ...from wrapped record
with pytest.raises(ValueError):
draft.id = "foo"
with pytest.raises(ValueError):
draft.pids = "foo"
# ...and also from wrapper itself
with pytest.raises(ValueError):
> draft.is_draft = "foo" # type: ignore
E Failed: DID NOT RAISE <class 'ValueError'>
tests/test_api.py:49: Failed
__________________________________________________________________ test_create_record ___________________________________________________________________
irdm = <iridium.api.Repository object at 0x7f083720ec00>, testutils = <class 'tests.conftest.UtilFuncs'>
dummy_file = <function dummy_file.<locals>._dummy_file at 0x7f08370ca8b0>
def test_create_record(irdm, testutils, dummy_file):
# edit/new version fails for invalid
with pytest.raises(httpx.HTTPStatusError):
irdm.drafts.create("INVALID_ID", True)
with pytest.raises(httpx.HTTPStatusError):
irdm.drafts.create("INVALID_ID", False)
time.sleep(1)
> assert len(irdm.drafts) == 0
E AssertionError: assert 1 == 0
E + where 1 = len(['k4dfb-gax02'])
E + where ['k4dfb-gax02'] = <iridium.api.Repository object at 0x7f083720ec00>.drafts
tests/test_api.py:87: AssertionError
__________________________________________________________________ test_record_queries __________________________________________________________________
rdm = <iridium.inveniordm.InvenioRDMClient object at 0x7f083723b400>
def test_record_queries(rdm):
"""Test queries to records."""
# check that there are no old pending drafts around
drafts = rdm.query.records(user=True, q="is_published:false")
> assert drafts.hits.total == 0
E AssertionError: assert 1 == 0
E + where 1 = { 'hits': [ { 'access': { 'embargo': {...},\n 'files': 'public',\n 're...,\n 'is_latest': False,\n 'is_latest_draft': True}}],\n 'total': 1}.total
E + where { 'hits': [ { 'access': { 'embargo': {...},\n 'files': 'public',\n 're...,\n 'is_latest': False,\n 'is_latest_draft': True}}],\n 'total': 1} = { 'hits': { 'hits': [ { 'access': {...},\n 'created': '2022-03-10T08:35:33.663943+00:00',\n ...': 'https://127.0.0.1/api/user/records?page=1&q=is_published%3Afalse&size=25&sort=bestmatch'},\n 'sortBy': 'bestmatch'}.hits
tests/test_inveniordm_api.py:57: AssertionError
================================================================ short test summary info ================================================================
FAILED tests/test_api.py::test_readonly_fields_draft - Failed: DID NOT RAISE <class 'ValueError'>
FAILED tests/test_api.py::test_create_record - AssertionError: assert 1 == 0
FAILED tests/test_inveniordm_api.py::test_record_queries - AssertionError: assert 1 == 0
============================================================= 3 failed, 11 passed in 17.03s =============================================================
Wrt:
> draft.is_draft = "foo" # type: ignore
E Failed: DID NOT RAISE <class 'ValueError'>
tests/test_api.py:49: Failed
It seems not to be possible to change the value, but it doesn't raise an error:
>>> irdm = Repository.connect("https://127.0.0.1", "OkRGeW1iQuki2pYDoTeFPCp3uMDMUPSk6fewRNRP7SDJOWb2qPK8JEcymKnu", verify=False)
>>> draft = irdm.drafts.create()
>>> print(draft)
{ 'access': { 'embargo': {'active': False},
'files': 'public',
'record': 'public',
'status': 'metadata-only'},
'created': '2022-03-10T09:09:06.035167+00:00',
'expires_at': '2022-03-10T09:09:06.035214',
'files': [],
'id': '9ramg-w1s84',
'is_draft': True,
'is_published': False,
'metadata': {},
'updated': '2022-03-10T09:09:06.059236+00:00',
'versions': {'index': 1, 'is_latest': False, 'is_latest_draft': True}}
>>> print(draft.is_published)
False
>>> draft.is_published=True
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/chriz/rz/code/invenio/repos/iridium/iridium/iridium/record.py", line 248, in __setattr__
return self._record.__setattr__(name, value)
File "/home/chriz/rz/code/invenio/repos/iridium/iridium/iridium/inveniordm/models/base.py", line 33, in __setattr__
raise ValueError(f"'{key}' is a read-only attribute!")
ValueError: 'is_published' is a read-only attribute!
>>> print(draft.is_draft)
True
>>> draft.is_draft=False
>>> print(draft.is_draft)
True
>>> draft.is_draft="foo"
>>> print(draft.is_draft)
True
>>>
Besides - the second and third test fail due to a missing cleanup after the fail of the first test.
These test in line 48-49 crashes. Thereafter, in line 71 a 'delete draft' is triggered - but with the crash not reached. The next method expects this draft to be deleted and since this is not the case two other tests are failing.
Tests are fixed for v8 in the most recent commit, thanks!
Looks like, there is an validation error. ;)
Maybe related: https://inveniordm.docs.cern.ch/releases/versions/version-v8.0.0/#my-dashboard
Edit: this seems to be an internal endpoint not an Rest-Api url-change.