Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: handle malformed backend responses. (#522)
When you delete a policy tag from a column in BigQuery, rather than
eliding the policyTag message entirely, it will return an empty
message (with no name field).  This change treats such responses
as equivalent to no PolicyTag message being present.
  • Loading branch information
shollyman committed Jul 10, 2020
1 parent f77e74e commit 64de23a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -60,6 +60,10 @@ com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags toPb() {

static PolicyTags fromPb(
com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags tagPb) {
return newBuilder().setNames(tagPb.getNames()).build();
// Treat a PolicyTag message without a Names subfield as invalid.
if (tagPb.getNames() != null) {
return newBuilder().setNames(tagPb.getNames()).build();
}
return null;
}
}
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;

import com.google.common.collect.ImmutableList;
import java.util.List;
Expand Down Expand Up @@ -46,6 +47,13 @@ public void testBuilder() {
assertNotEquals(POLICY_TAGS, POLICIES);
}

@Test
public void testWithoutNames() {
com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags PARTIALTAG =
new com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags();
assertNull(PolicyTags.fromPb(PARTIALTAG));
}

@Test
public void testFromAndPb() {
assertEquals(POLICY_TAGS, PolicyTags.fromPb(POLICY_TAGS.toPb()));
Expand Down

0 comments on commit 64de23a

Please sign in to comment.