GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PubSub topic.create method should raise a Conflict error instead of RetryError/GaxError when topic exists · Issue #3175 · googleapis/google-cloud-python

PubSub topic.create method should raise a Conflict error instead of RetryError/GaxError when topic exists #3175

New issue
Copy link
New issue
Copy link
Closed
#3443
Closed
PubSub topic.create method should raise a Conflict error instead of RetryError/GaxError when topic exists#3175
#3443
Copy link
Assignees
lukesneeringer
Labels
api: coreapi: pubsubIssues related to the Pub/Sub API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.

Description

@lucmult
lucmult
opened on Mar 21, 2017
Issue body actions

Following the documentation from PubSub site if you run the example 2x it will generate the error:

GaxError(Exception occurred in retry method that was not classified as transient, caused by <_Rendezvous of RPC that terminated with (StatusCode.ALREADY_EXISTS, Resource already exists in the project (resource=my-new-topic).)>) <class 'google.gax.errors.RetryError'>

However it should raise Conflict Error (google.cloud.exceptions.Conflict), because the API returns a 409 response.
You can see the status code using API Explorer:
https://developers.google.com/apis-explorer/#search/pubsub/pubsub/v1/pubsub.projects.topics.create

409  
{
 "error": {
  "code": 409,
  "message": "Resource already exists in the project (resource=my-new-topic).",
  "status": "ALREADY_EXISTS",
...
  }
}

Full traceback on Python:

>>> topic.create()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/google/home/lucmult/.virtualenvs/pubsub/local/lib/python2.7/site-packages/google/cloud/pubsub/topic.py", line 155, in create
    api.topic_create(topic_path=self.full_name)
  File "/usr/local/google/home/lucmult/.virtualenvs/pubsub/local/lib/python2.7/site-packages/google/cloud/pubsub/_gax.py", line 104, in topic_create
    topic_pb = self._gax_api.create_topic(topic_path)
  File "/usr/local/google/home/lucmult/.virtualenvs/pubsub/local/lib/python2.7/site-packages/google/cloud/gapic/pubsub/v1/publisher_client.py", line 278, in create_topic
    return self._create_topic(request, options)
  File "/usr/local/google/home/lucmult/.virtualenvs/pubsub/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 419, in inner
    return api_caller(api_call, this_settings, request)
  File "/usr/local/google/home/lucmult/.virtualenvs/pubsub/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 407, in base_caller
    return api_call(*args)
  File "/usr/local/google/home/lucmult/.virtualenvs/pubsub/local/lib/python2.7/site-packages/google/gax/api_callable.py", line 368, in inner
    return a_func(*args, **kwargs)
  File "/usr/local/google/home/lucmult/.virtualenvs/pubsub/local/lib/python2.7/site-packages/google/gax/retry.py", line 126, in inner
    ' classified as transient', exception)
google.gax.errors.RetryError: GaxError(Exception occurred in retry method that was not classified as transient, caused by <_Rendezvous of RPC that terminated with (StatusCode.ALREADY_EXISTS, Resource already exists in the project (resource=my-new-topic).)>)

Activity

  1. dhermes commented on Mar 21, 2017

    @dhermes
    dhermes
    on Mar 21, 2017
    Contributor
    More actions

    @lukesneeringer This is part of a more general question: how / where should we re-wrap GaxError?

  2. lucmult commented on Mar 21, 2017

    @lucmult
    lucmult
    on Mar 21, 2017
    ContributorAuthor
    More actions

    For anybody affected by this, to handle ALREADY_EXISTS exception you can use the following scheme:

    try:
      # create topic
    except Conflict as error:
       # handle the current conflict exception
    except RetryException as error:
       status_code = error.cause.code()
       if status_code == status_code.ALREADY_EXISTS:
          # handle the already exists
       else:
          # nothing that we want just re-raise the exception
          raise
  3. lukesneeringer commented on Mar 21, 2017

    @lukesneeringer
    lukesneeringer
    on Mar 21, 2017
    Contributor
    More actions

    @lukesneeringer This is part of a more general question: how / where should we re-wrap GaxError?

    The correct answer is to have GAX raise these different kinds of errors, rather than the catch-all GaxError. It could import them from google.cloud.exceptions.

  4. lukesneeringer
    self-assigned this
    on Mar 21, 2017
  5. lukesneeringer
    added
    api: core
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    status: acknowledged
    on Mar 21, 2017
  6. dhermes commented on Mar 21, 2017

    @dhermes
    dhermes
    on Mar 21, 2017
    Contributor
    More actions

    @lukesneeringer That would be much preferred to the current ad-hoc approach (only in use in one subpackage, though some other remappings also exist).

  7. marcboissonneaultjda commented on Mar 29, 2017

    @marcboissonneaultjda
    marcboissonneaultjda
    on Mar 29, 2017
    More actions

    @dhermes While your team is fixing the issue, can you to fix the subscription_create issue at the same time?
    It's exactly the same issue but for subscription and I completely forgot to mention it in my support case with @lucmult

  8. tseaver commented on May 19, 2017

    @tseaver
    tseaver
    on May 19, 2017
    Contributor
    More actions

    @lukesneeringer Generalizing the solution from datastore requires moving datastore._gax._catch_remap_gax_error into core, most obviously core.exceptions. Doing that requires adding a from google.cloud.core to google.gax. We have unconditional dependencies to google.gax in other packages: would that be a problem for core?

  9. tseaver
    added
    api: pubsubIssues related to the Pub/Sub API.
    on May 19, 2017
  10. tseaver commented on May 19, 2017

    @tseaver
    tseaver
    on May 19, 2017
    Contributor
    More actions

    The issue within pubsub seems to be that the back-end API shifted from returning FAILED_PRECONDITION to ALREADY_EXISTS: we have handling which raises Conflict for the older code.

    We should add a system test (or extend and existing one) to ensure that we don't regress whatever fix we apply now.

  11. tseaver
    closed this as completedin #3443on Jun 7, 2017
  12. tseaver
    added a commit that references this issue on Jun 7, 2017

    Remap new Gax conflict error code (#3443)

    This issue will close once commit 8dacdb9 is merged into the 'main' branch.
    8dacdb9
  13. landrito
    added 3 commits that reference this issue on Aug 21, 2017

    Remap new Gax conflict error code (googleapis#3443)

    This issue will close once commit 40e7cf4 is merged into the 'master' branch.
    40e7cf4

    Remap new Gax conflict error code (googleapis#3443)

    This issue will close once commit 4571b52 is merged into the 'master' branch.
    4571b52

    Remap new Gax conflict error code (googleapis#3443)

    This issue will close once commit 33b007c is merged into the 'master' branch.
    33b007c
  14. Saurav-Jain16 commented on Jan 19, 2019

    @Saurav-Jain16
    Saurav-Jain16
    on Jan 19, 2019
    More actions

    Error is coming in below code when starting the server "(node:6924) UnhandledPromiseRejectionWarning: Error: 6 ALREADY_EXISTS: Resource already exists in the project (resource=serverone)."

    Any idea why this issue is coming. Same code is working on other server

    'use strict';

    const http = require('http');

    // Imports the Google Cloud client library
    const PubSub = require('@google-cloud/pubsub');

    // Your Google Cloud Platform project ID
    const projectId = 'projectId';

    // Instantiates a client
    const pubsub = PubSub({
    projectId: projectId,
    keyFilename:'keyFilename.json'
    });

    // Reference a topic that has been previously created.
    var topic = pubsub.topic('dashboardConnector');

    createFlowControlledSubscription('dashboardConnector','serverone',1,10000);

    function createFlowControlledSubscription (topicName, subscriptionName, maxInProgress, maxBytes) {
    // Instantiates a client
    // const pubsub = PubSub();

    // References an existing topic, e.g. "my-topic"
    const topic = pubsub.topic(topicName);

    // Creates a new subscription, e.g. "my-new-subscription"
    // Note that flow control configurations are not persistent
    return topic.createSubscription(subscriptionName, {
    flowControl: {
    maxBytes: maxBytes,
    maxMessages: maxInProgress
    }
    })
    .then((results) => {
    const subscription = results[0];

      subscription.on('message', function(message) {
        var attrs=message.attributes;
        var data =JSON.parse(message.data.toString('utf8'));
    
         
    	
           message.ack();
        });
    
      console.log(`Subscription ${subscription.name} created with a maximum of ${maxInProgress} unprocessed messages.`);
      return subscription;
    });
    

    }

  15. parthea
    added a commit that references this issue on Nov 24, 2025

    Remap new Gax conflict error code (#3443)

    This issue will close once commit b3cdb18 is merged into the 'main' branch.
    b3cdb18
  16. parthea
    added a commit that references this issue on Mar 2, 2026

    Remap new Gax conflict error code (#3443)

    This issue will close once commit 2742e9c is merged into the 'main' branch.
    2742e9c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @lukesneeringer
    lukesneeringer

Labels

api: coreapi: pubsubIssues related to the Pub/Sub API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.