Skip to content
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

Adding a tag to a table without metadata, breaks metadata editor #1882

Open
1 task done
ebroda opened this issue Oct 1, 2024 · 0 comments
Open
1 task done

Adding a tag to a table without metadata, breaks metadata editor #1882

ebroda opened this issue Oct 1, 2024 · 0 comments
Labels

Comments

@ebroda
Copy link
Contributor

ebroda commented Oct 1, 2024

Description of the issue

If you create a new table, add a tag and then try to edit it's metadata, this fails.

Javascript is throwing an error: Uncaught TypeError: can't convert undefined to object

It's fine before adding the tag. Looks like something is happening there, which the javascript (metaedit.js) does not like.

Steps to Reproduce

  1. Create a new table, e.g. using https://openenergyplatform.org/dataedit/wizard/
  2. Visit Edit Metadata, should work (e.g. https://openenergyplatform.org/dataedit/view/model_draft/test_v2353456/meta_edit).
  3. Currently, also https://openenergyplatform.org/api/v0/schema/model_draft/tables/test_v2353456/meta/, delievers only 2 bytes = {} (= no metadata defined).
  4. Now assign a tag on the right.
  5. Try to edit the metadata. Fails with above exception (and an endless loading spinner).
  6. And the call for https://openenergyplatform.org/api/v0/schema/model_draft/tables/test_v2353456/meta/ delivers now 2885 bytes and a whole meta structure for the entry.

Ideas of solution

  • Fix the javascript function.

And now a bit more of architectural thing:

  • It seems, that currently most of the metadata is build in the Javascript functions of metaedit.js. But at the same time, adding a tag also creates the structure, but it looks like there's some small difference. So why is it necessary to create the structure in the js, if we have a function in the django backend which can create at least the basic structure from table data? Why not use this data, to provide a basic structure directly as json even if the data does not exist on the server?

I also did a quick check comparing the two json structures, and there basically identical. There are no different keys, only the tag-version has a few more sub attributes.

Dig into concrete problem

function fixRecursive(schemaProps, elemObject, path) {
// is object ?
if (typeof elemObject != 'object' || $.isArray(elemObject)) {
return;
}
// for each key: fill missing (recursively)
Object.keys(schemaProps).map(function(key) {

So I added some debug code to fixRecursive, before line 142:

console.log(path, elemObject, schemaProps);

And this leads gives some output and ends with:

root.resources.0.schema.foreignKeys.0.fields.0 null undefined

Interesting here is, that elemObject, which is checked previously is null.
So one idea would be, adding a check for that to line 140.

if (elemObject == null || typeof elemObject != 'object' || $.isArray(elemObject)) {

And with that, the editor is shown directly as for other basic metadata. But if you now enter some data, this data is not submittable. (see next issue).

Context and Environment

  • Version used: current oep
  • Operating system: -
  • Environment setup and (python) version:-

Workflow checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant