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

get_registry_record errors even if default value is given #417

Open
fredvd opened this issue Oct 30, 2018 · 3 comments
Open

get_registry_record errors even if default value is given #417

fredvd opened this issue Oct 30, 2018 · 3 comments

Comments

@fredvd
Copy link
Member

fredvd commented Oct 30, 2018

expected behavior:

When I query a record that is not yet loaded in the registry by running an upgrade step which reads in registry records defined by xml or a zope.schema interface, I should receive a default parameter if I passed that into the get_registry_record function call

What happens:

if interface is not None:
records = registry.forInterface(interface)
_marker = object()
if getattr(records, name, _marker) != _marker:
return registry['{0}.{1}'.format(interface.__identifier__, name)]
if default is not MISSING:
return default

The function already errors on L300 when the forInterface() call cannot find my schema, L305 is never reached in this case.

  Module plone.api.portal, line 2, in get_registry_record
  Module plone.api.validation, line 77, in wrapped
  Module plone.api.portal, line 300, in get_registry_record
  Module plone.registry.registry, line 78, in forInterface
KeyError: 'Interface `myproject.content.interfaces.IProjectSettings` defines a field `somefield`, for which there is no record.'

@fredvd
Copy link
Member Author

fredvd commented Oct 30, 2018

Whoops, wrong assumption. My IProjectSettings was already loaded in the registry, but I added a new field. And plone.registry.forInterface is checking if all fields from the Interface are loaded in the registry, which is not the case.

My suggested solution would be to pass 'check=False' to the forInterface call on L300, which will skip the field verification:

https://github.com/plone/plone.registry/blob/3d5c54a8cb100f882d0b4fa592f86a16a5cfba4e/plone/registry/registry.py#L67-L79

But this will throw a KeyError next on L303 , so that would have to be Exception handled as well. Nasty stuff.

@djay
Copy link
Member

djay commented Nov 23, 2023

@fredvd I think what it needs is modifed records proxy that returns the schema defaults if the data is missing

@djay
Copy link
Member

djay commented Nov 24, 2023

@fredvd I created a fix for the same problem in the restapi. it probably needs a similar fix here, or a combined fix somewhere else - plone/plone.restapi#1736

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

No branches or pull requests

2 participants