<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def upsert_sweep(self, config):
 """Upsert a sweep object. Args: config (str):
 sweep config (will be converted to yaml) """

        mutation = gql('''
        mutation UpsertSweep(
            $config: String,
            $description: String,
            $entityName: String!,
            $projectName: String!
        ) {
            upsertSweep(input: {
                config: $config,
                description: $description,
                entityName: $entityName,
                projectName: $projectName
            }) {
                sweep {
                    name
                }
            }
        }
        ''')

        # don't retry on validation errors
        # TODO(jhr): generalize error handling routines
        def no_retry_400_or_404(e):
            if not isinstance(e, requests.HTTPError):
                return True
            if e.response.status_code != 400 and e.response.status_code != 404:
                return True
            body = json.loads(e.response.content)
            raise UsageError(body['errors'][0]['message'])

        response = self.gql(mutation, variable_values={
            'config': yaml.dump(config),
            'description': config.get("description"),
            'entityName': self.settings("entity"),
            'projectName': self.settings("project")},
            check_retry_fn=no_retry_400_or_404)
        return response['upsertSweep']['sweep']['name']