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

Clean up the ._resource field in the models #187

Open
kevinhillinger opened this issue Mar 2, 2023 · 1 comment
Open

Clean up the ._resource field in the models #187

kevinhillinger opened this issue Mar 2, 2023 · 1 comment
Labels
backend Needs backend work help wanted Extra attention is needed

Comments

@kevinhillinger
Copy link
Member

@dciborow submitted PR for #186 noting the issue with the syntax and that it violated linting rules.

Link to comment thread

We need to continue to support out of the box behavior that the CLI gives us inheriting from msrest.serialization.Model while having a pythonic and clean way for it to ignore the field when serializing out from the CLI.

@kevinhillinger kevinhillinger added help wanted Extra attention is needed backend Needs backend work labels Mar 2, 2023
@dciborow
Copy link
Contributor

dciborow commented Mar 2, 2023

Option 1: Rename _resource -> resource

class Offer(Model):
    _attribute_map = {
        'id': {'key': 'id', 'type': 'str'},
        'alias': {'key': 'alias', 'type': 'str'},
        'type': {'key': 'type', 'type': 'str'}
    }

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.id = kwargs.get('id', None)
        self.alias = kwargs.get('alias', None)
        self.type = kwargs.get('type', None)
        self._resource = kwargs.get('resource', None)

Usage: offer_resource_id = offer.resource.durable_id

But, then we should consider if the field should be adjusted the same way in 'Plan' and 'PlanListing'.

Option 2: Add method to retrieve durable_id

class Offer(Model):
    _attribute_map = {
        'id': {'key': 'id', 'type': 'str'},
        'alias': {'key': 'alias', 'type': 'str'},
        'type': {'key': 'type', 'type': 'str'}
    }

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.id = kwargs.get('id', None)
        self.alias = kwargs.get('alias', None)
        self.type = kwargs.get('type', None)
        self._resource = kwargs.get('resource', None)

    def durable_id(self):
        return self._resource.durable_id

Usage: offer_resource_id = offer.durable_id

This PR in my fork demos what this change would look like - https://github.com/dciborow/partnercenter-cli-extension/pull/15/files

(this is more pythonic then making a function def resource(self): return self._resource)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Needs backend work help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants