#426 RFE: In the result munch, store a reference to the used proxy object
Closed 5 years ago by frostyx. Opened 5 years ago by frostyx.

The same way, that we currently store a reference to the response object (result.__response__), we might want to store a reference to the proxy object.

from copr.v3 import Client
client = Client.create_from_config_file()
build = client.build_proxy.get(123)

# Imagine this line done internally in the `build_proxy.get` method
# Actually, by all proxy methods
build.__proxy__ = client.build_proxy

This will mainly allow one thing - Obtaining a new version of an object, based just on itself.

build.__proxy__.get(build.id).id
123

There are many practical applications of this, which can be implemented by us or third-party.

  • wait method proposed in PR#414. It requires an unfriendly build_proxy parameter, to be able to obtain the current build status.
  • In the APIv3 prototype, there was an idea of refresh method, that would take a munch result and return its current version (e.g. refreshing a build munch, to get the current status).
  • Some sort of hybrid objects with cached permanent attributes (e.g. ID, owner, etc) and live attributes (e.g. build status) returning always the current frontend value.

I am not saying, that we can't live without these, neither that I want to implement them (except for the first one). But it might be useful for some people / some use-cases.

Why __response__ object is not enough?
In the particular example shown in this issue, it is possible to do

import requests
from copr.v3.requests import munchify  # Not part of the API
session = requests.Session()
result = session.send(build.__response__.request)
munchify(result)

but this approach is not versatile enough. It works only when the original munch was returned by a get method. If it was returned from e.g. create_from_url, it will create a new build on each call, which is not the wanted behavior.

Do we want the result.__proxy__ reference? Is there any reason why not?


Metadata Update from @frostyx:
- Issue tagged with: API

5 years ago

Metadata Update from @frostyx:
- Issue tagged with: RFE

5 years ago

Merged, I am closing this issue.

Metadata Update from @frostyx:
- Issue status updated to: Closed (was: Open)

5 years ago

Login to comment on this ticket.

Metadata