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

Avoid KeyError when tile schema has changed #825

Merged
merged 1 commit into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ There's a frood who really knows where his towel is.
2.0b2 (unreleased)
^^^^^^^^^^^^^^^^^^

- Avoid ``KeyError`` when tile schema has changed (refs. `brasil.gov.portal#524 <https://github.com/plonegovbr/brasil.gov.portal/issues/524>`_).
[hvelarde]

- Fix package uninstall.
[hvelarde]

Expand Down
10 changes: 7 additions & 3 deletions src/collective/cover/tiles/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ def applyTileConfigurations(self):
conf = self.tile.get_tile_configuration()
if self.tileType:
fields = getFields(self.tileType.schema)

for field_name, field_conf in conf.items():
if 'order' in field_conf and field_conf['order']:
fields[field_name].order = int(field_conf['order'])
if field_name not in fields:
continue # tile schema has changed

if not isinstance(field_conf, dict):
Copy link
Member

Choose a reason for hiding this comment

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

in what case this is not a dict?

Copy link
Member Author

Choose a reason for hiding this comment

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

(Pdb) pp conf.items()
[('css_class', ''),
 ('link_url', {'htmltag': u'h2', 'order': u'2', 'visibility': u'on'}),
 ('link_text', {'htmltag': u'h2', 'order': u'1', 'visibility': u'on'}),
 ('title', {'htmltag': u'h2', 'order': u'0', 'visibility': u'on'})]

continue # field is not ordered

fields[field_name].order = int(field_conf.get('order', 0))

def set(self, data):
# when setting data, we need to purge scales/image data...
Expand Down