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

Add option for lazy-loading fields #835

Closed
nickwilliams-eventbrite opened this issue Sep 2, 2019 · 2 comments · Fixed by #1205
Closed

Add option for lazy-loading fields #835

nickwilliams-eventbrite opened this issue Sep 2, 2019 · 2 comments · Fixed by #1205
Labels

Comments

@nickwilliams-eventbrite
Copy link

The JIRA class constructor provides several fields to prevent (or enable) initially connecting to JIRA to get information from it. For example, get_server_info will enable connecting to get server information if True, but disable it if False.

However, the end of the constructor has this code:

        self._fields = {}
        for f in self.fields():
            if 'clauseNames' in f:
                for name in f['clauseNames']:
                    self._fields[name] = f['id']

This makes it impossible to construct a JIRA object without connecting to JIRA, even if you have set the 2-3 "check things" arguments to False. In a test or development environment, it's common to have dummy/do-nothing configurations for such things, and stub out or patch the code doing the actual connection/calling, but when you can't even construct an object without connecting, it makes testing more difficult. Not impossible, mind you, just more difficult.

Additionally, self._fields is, currently, only used while searching, so connecting and retrieving this information eagerly wastes I/O if you aren't going to use the JIRA instance for searching.

I propose making self._fields be a lazy-loading property, instead. It would be compatible with all code currently using self._fields, but it would delay connecting and retrieving this field information util necessary.

    @property
    def _fields(self):
        if not hasattr(self, '_fields_value'):
            self._fields_value = {}
            for f in self.fields():
                if 'clauseNames' in f:
                    for name in f['clauseNames']:
                        self._fields_value[name] = f['id']
        return self._fields_value
@stale
Copy link

stale bot commented Dec 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You way want to consider using the Sponsor button in order to persuade someone to address it.

@stale stale bot added the stale Ticket that is likely to go nowhere and that will be closed soon label Dec 1, 2019
@nickwilliams-eventbrite
Copy link
Author

Stalebot, please remove the stale label. An issue does not become stale just because it's not acknowledged/replied to.

@stale stale bot removed the stale Ticket that is likely to go nowhere and that will be closed soon label Dec 2, 2019
@adehad adehad added the feature label Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants