Skip to content
Permalink
Browse files
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 64de23a95736ffaaae7a05e0fd2c6f5f8c5c3665
@@ -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;
}
}
@@ -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;
@@ -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()));

0 comments on commit 64de23a

Please sign in to comment.