<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_by_symbol(self, symbol: str) -> Commodity: """ Returns the commodity with the given symbol. If more are found, an exception will be thrown. """

        # handle namespace. Accept GnuCash and Yahoo-style symbols.
        full_symbol = self.__parse_gc_symbol(symbol)

        query = (
            self.query
            .filter(Commodity.mnemonic == full_symbol["mnemonic"])
        )
        if full_symbol["namespace"]:
            query = query.filter(Commodity.namespace == full_symbol["namespace"])

        return query.first()