Skip to content

Conversation

@max-zilla
Copy link
Contributor

Adds additional metadata features including deleting, PUT and PATCH, more validation on metadata definitions.

@max-zilla max-zilla requested review from lmarini and longshuicy May 18, 2022 15:11
try:
contents[field.name] = t(contents[field.name])
except ValueError:
if field.list and type(value) is list:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the value is not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Metadata document that was added to database
"""
if (file := await db["files"].find_one({"_id": ObjectId(file_id)})) is not None:
md = _build_metadata_db_obj(db, metadata_in, FileOut(**file))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error here

 File "/Users/cwang138/Documents/Clowder/clowder2/backend/app/routers/metadata_files.py", line 98, in add_file_metadata
    md = _build_metadata_db_obj(db, metadata_in, FileOut(**file), user)
TypeError: _build_metadata_db_obj() missing 1 required positional argument: 'user'

when trying to attach metadata to a file:

{
  "definition": "LatLon",
  "contents": {
  	"longitude":40.123,
  	"latitude":-88.777
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be fixed



@router.patch("/{dataset_id}/metadata", response_model=MetadataOut)
async def update_dataset_metadata(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to patch an exist metadata entry by giving the "definition", "metadata id" as well as the "contents". But somehow it's not patching the correct metadata?

My request is

{"id":"628664405685a1694705c863","definition":"LatLon","contents":{"latitude":"111","longitude":"222"}}

and my response is on another metadata definition:

{"id":"6286642c5685a1694705c85f","context":null,"context_url":"clowder.org","definition":null,"contents":{"color":"blue","latitude":"111","longitude":"222"},"resource":{"collection":"datasets","resource_id":"627a8d09ca3d2920a17f602a","version":null},"agent":{"id":"6286642c5685a1694705c860","creator":{"id":"627a8d01ca3d2920a17f6025","email":"[email protected]","first_name":"Chen","last_name":"Wang"},"extractor":null},"created":"2022-05-19T15:37:16.065000"}

definition = metadata_in.definition
if definition is not None:
existing_q = {
"resource.resource_id": dataset.id,
Copy link
Member

@longshuicy longshuicy May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error complaing that dict object doesn't have id field and I looked at the object it has "_id" instead:
image

I could fix it on but then i looked at similar endpoints on metadata_file.py and saw you are using file.id there and it worked... No sure what's going on here? @max-zilla

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually i know... it's missing dataset = DatasetOut(**dataset).

@max-zilla max-zilla merged commit 145927d into main Jun 3, 2022
@longshuicy longshuicy linked an issue Jun 10, 2022 that may be closed by this pull request
@max-zilla max-zilla deleted the metadata-updates branch October 31, 2022 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Match metadata in frontend

3 participants