Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Equal operator in table constraints class throws error when instance in None #2174

@AnasBalk

Description

@AnasBalk

Equal operator in table constraints class throws error when instance in None

Code issue equal operator

class TableConstraints:
    """The TableConstraints defines the primary key and foreign key.

    Args:
        primary_key:
            Represents a primary key constraint on a table's columns. Present only if the table
            has a primary key. The primary key is not enforced.
        foreign_keys:
            Present only if the table has a foreign key. The foreign key is not enforced.

    """

    def __init__(
        self,
        primary_key: Optional[PrimaryKey],
        foreign_keys: Optional[List[ForeignKey]],
    ):
        self.primary_key = primary_key
        self.foreign_keys = foreign_keys

    def __eq__(self, other):
        if not isinstance(other, TableConstraints) and other is not None:
            raise TypeError("The value provided is not a BigQuery TableConstraints.")
        return (
            self.primary_key == other.primary_key if other.primary_key else None
        ) and (self.foreign_keys == other.foreign_keys if other.foreign_keys else None)```

#### Stack trace

fix

class TableConstraints:
"""The TableConstraints defines the primary key and foreign key.

Args:
    primary_key:
        Represents a primary key constraint on a table's columns. Present only if the table
        has a primary key. The primary key is not enforced.
    foreign_keys:
        Present only if the table has a foreign key. The foreign key is not enforced.

"""

def __init__(
    self,
    primary_key: Optional[PrimaryKey],
    foreign_keys: Optional[List[ForeignKey]],
):
    self.primary_key = primary_key
    self.foreign_keys = foreign_keys

def __eq__(self, other):
    if not isinstance(other, TableConstraints) and other is not None:
        raise TypeError("The value provided is not a BigQuery TableConstraints.")
    return (
        self.primary_key == other.primary_key if other and other.primary_key else None
    ) and (self.foreign_keys == other.foreign_keys if other.foreign_keys else None)

Thanks!

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions