prefect icon indicating copy to clipboard operation
prefect copied to clipboard

Unable to update variable in UI or using python sdk even when using overwrite=True - Error 'A variable with the name "the_answer" already exists.'

Open taylor-curran opened this issue 1 year ago • 2 comments

First check

  • [X] I added a descriptive title to this issue.
  • [X] I used the GitHub search to find a similar issue and didn't find it.
  • [X] I searched the Prefect documentation for this issue.
  • [X] I checked that this issue is related to Prefect and not one of its dependencies.

Bug summary

Updating existing variables appears to broken both in the UI and via the python sdk. image

I use overwrite=True but still see the error "A variable with the name 'the_answer' already exists."

# update a variable
answer = Variable.set(name="the_answer", value="43", overwrite=True)
print(answer.value)

I tried out the example from Prefect's release notes v2.17.0 and see this error.

Reproduction

First run:


from prefect.variables import Variable

# set a variable
variable = Variable.set(name="the_answer", value="42")

Then:

from prefect.variables import Variable

# get a variable
answer = Variable.get('the_answer')
print(answer.value)
# 42

And finally run:

from prefect.variables import Variable

# update a variable
answer = Variable.set(name="the_answer", value="43", overwrite=True)
print(answer.value)
#43

Error

Traceback (most recent call last):
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/odsc/with_pref/vars.py", line 12, in <module>
    answer = Variable.set(name="the_answer", value="43", overwrite=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 300, in coroutine_wrapper
    return call()
           ^^^^^^
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 432, in __call__
    return self.result()
           ^^^^^^^^^^^^^
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 318, in result
    return self.future.result(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 179, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 389, in _run_async
    result = await coro
             ^^^^^^^^^^
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/variables.py", line 58, in set
    await client.update_variable(variable=var)
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/client/orchestration.py", line 2962, in update_variable
    await self._client.patch(
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/httpx/_client.py", line 1966, in patch
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/httpx/_client.py", line 1574, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/client/base.py", line 356, in send
    response.raise_for_status()
  File "/Users/taylorcurran/Documents/kevin/prefect-demos/.venv/lib/python3.12/site-packages/prefect/client/base.py", line 169, in raise_for_status
    raise PrefectHTTPStatusError.from_httpx_error(exc) from exc.__cause__
prefect.exceptions.PrefectHTTPStatusError: Client error '409 Conflict' for url 'https://api.prefect.cloud/api/accounts/0ff44498-d380-4d7b-bd68-9b52da03823f/workspaces/e30d4419-8433-4a8f-815d-06c4b43ab225/variables/name/the_answer'
Response: {'detail': "A variable with the name 'the_answer' already exists."}
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409

Versions

Version:             2.18.3
API version:         0.8.4
Python version:      3.12.2
Git commit:          c449aee8
Built:               Thu, May 2, 2024 5:47 PM
OS/Arch:             darwin/arm64
Profile:             se-demos
Server type:         cloud

Additional context

No response

taylor-curran avatar May 09 '24 15:05 taylor-curran

Had a call with a customer experiencing the same issue earlier today, and I'm able to reproduce it on my end as well. The same error shows up when trying to edit a variable in the UI.

mthatt avatar May 09 '24 20:05 mthatt

Thank @mthatt I can confirm its not working in the UI -- I'll edit the issue above to reflect this. image

taylor-curran avatar May 09 '24 20:05 taylor-curran

@taylor-curran - I believe this has been fixed (and I can no longer recreate so I am closing this issue.) Please let me know if I am missing something!

zhen0 avatar May 20 '24 21:05 zhen0