box / box-python-sdk

Box SDK for Python
http://opensource.box.com/box-python-sdk/
Apache License 2.0
417 stars 214 forks source link

get_previous_versions does not retrieve etag fields #820

Closed ronaldoapsilva closed 1 year ago

ronaldoapsilva commented 1 year ago

Hi there,

I have passed the param 'fields' to get 'etag' for the list of previous version, but I got an error below. How Should pass the params 'fields' to get 'etag' for all previous version?

...
  file_versions = self.client.file(file_id).get_previous_versions(
      limit=5, fields=['id', 'created_at', 'etag']
  )

  all_files = [
      {'id': version.id, 'created_at': version.created_at, 'etag': version.etag}
      for version in file_versions
  ]
  return all_files

....
  File "c:\Users\111942631\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\111942631\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "c:\Users\111942631\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\111942631\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "C:\GitEnterprise\MY-TEMPLATES\Template-Box\no_hard_code\box_app.py", line 140, in <module>
    files = box_app.get_previous_versions(file_id)
  File "C:\GitEnterprise\MY-TEMPLATES\Template-Box\no_hard_code\box_app.py", line 40, in get_previous_versions
    all_files = [
  File "C:\GitEnterprise\MY-TEMPLATES\Template-Box\no_hard_code\box_app.py", line 41, in <listcomp>
    {'id': version.id, 'created_at': version.created_at, 'etag': version.etag}
AttributeError: 'FileVersion' object has no attribute 'etag'

(.venv) c:\GitEnterprise\MY-TEMPLATES\Template-Box>
lukaszsocha2 commented 1 year ago

Hi @ronaldoapsilva, etag is not a valid field of File Version, that is why it is not returned. To see all available field for File Version see API documentation: https://developer.box.com/reference/resources/file-version--full/. Best, @lukaszsocha2

ronaldoapsilva commented 1 year ago

Thank you @lukaszsocha2 !

The field 'version_number' on documention for the link that you provide will for me.