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

Improve schema nesting #97

Merged
merged 15 commits into from
Nov 2, 2020
Merged

Improve schema nesting #97

merged 15 commits into from
Nov 2, 2020

Conversation

rbw
Copy link
Owner

@rbw rbw commented Oct 26, 2020

Adds support for any level of nesting and fixes bugs related to fetching of nested objects and how they are merged with the main document.

Model declaration

class ProductCatalogItem(ModelSchema):
    sys_id = aiosnow.fields.String()
    no_order_now = aiosnow.fields.Boolean()
    delivery_time = aiosnow.fields.DateTime()
    sys_name = aiosnow.fields.String()


class HardwareModel(ModelSchema):
    sys_id = aiosnow.fields.String()
    name = aiosnow.fields.String()
    manufacturer = aiosnow.fields.StringMap()
    model_number = aiosnow.fields.String()
    barcode = aiosnow.fields.String()
    power_consumption = aiosnow.fields.Integer()
    rack_units = aiosnow.fields.Integer()
    product_catalog_item = ProductCatalogItem


class Hardware(aiosnow.TableModel):
    sys_id = aiosnow.fields.String(is_primary=True)
    asset_tag = aiosnow.fields.String()
    install_status = aiosnow.fields.StringMap()
    location = aiosnow.fields.String(pluck=Pluck.DISPLAY_VALUE)
    company = aiosnow.fields.StringMap()
    ci = aiosnow.fields.String(pluck=Pluck.DISPLAY_VALUE)
    serial_number = aiosnow.fields.String()
    model = HardwareModel
    sys_class_name = aiosnow.fields.String(pluck=Pluck.DISPLAY_VALUE)
    product_catalog_item = ProductCatalogItem

Response data

[ { 'asset_tag': 'P1000479',
    'ci': 'MacBook Pro 15"',
    'company': <StringMapping [key=81fdf9ebac1d55eb4cb89f136a082555, value=ACME China]>,
    'install_status': <StringMapping [key=1, value=In use]>,
    'location': '2500 West Daming Road, Shanghai',
    'model': { 'barcode': 'MD318LL/A',
               'manufacturer': <StringMapping [key=b7e9e843c0a80169009a5a485bb2a2b5, value=Apple]>,
               'model_number': 'MD318LL/A',
               'name': 'MacBook Pro 15"',
               'power_consumption': None,
               'product_catalog_item': { 'delivery_time': datetime.datetime(1970, 1, 3, 0, 0),
                                         'no_order_now': False,
                                         'sys_id': '2ab7077237153000158bbfc8bcbe5da9',
                                         'sys_name': 'Apple MacBook Pro 15"'},
               'rack_units': 1,
               'sys_id': 'd501454f1b1310002502fbcd2c071334'},
    'product_catalog_item': { 'delivery_time': datetime.datetime(1970, 1, 3, 0, 0),
                              'no_order_now': False,
                              'sys_id': '2ab7077237153000158bbfc8bcbe5da9',
                              'sys_name': 'Apple MacBook Pro 15"'},
    'serial_number': 'BQP-854-D33246-GH',
    'sys_class_name': 'Hardware',
    'sys_id': 'd501454f1b1310002502fbcd2c071334'}]

This takes care of some bugs related to fetching
of nested objects and how they are merged with the
main document
@rbw rbw linked an issue Oct 26, 2020 that may be closed by this pull request
@rbw rbw mentioned this pull request Oct 26, 2020
rbw added 11 commits October 26, 2020 23:23
Update BaseModelMeta to check for field name conflicts
in non-BaseField members only
Move BaseField registration code in ModelSchema to ModelSchemaMeta
- Fixes issue with cached resources not getting
accessed correctly
- Implements cache lifetime, default to 20 secs
@rbw rbw merged commit fd1846b into master Nov 2, 2020
@rbw rbw deleted the improve-schema-nesting branch November 2, 2020 11:49
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.

Double nested fields
1 participant