Changeset - 69f3e4ee6eeb
[Not reviewed]
0 2 0
Brett Smith - 3 years ago 2021-03-15 13:56:13
brettcsmith@brettcsmith.org
query: Add a hint for the TypeError `unhashable type: 'set'`.
2 files changed with 27 insertions and 10 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/query.py
Show inline comments
...
 
@@ -547,41 +547,58 @@ class BQLShell(bc_query_shell.BQLShell):
 
            )
 
            logger.debug("executing query")
 
            row_types, rows = bc_query_execute.execute_query(
 
                compiled_query, self.entries, self.options_map,
 
            )
 
            if self.vars['numberify']:
 
                logger.debug("numberifying query")
 
                row_types, rows = bc_query_numberify.numberify_results(
 
                    row_types, rows, self.options_map['dcontext'].build(),
 
                )
 
        except Exception as error:
 
            logger.error(str(error), exc_info=logger.isEnabledFor(logging.DEBUG))
 
            if (isinstance(error, TypeError)
 
                and error.args
 
                and ' not supported between instances ' in error.args[0]):
 
                logger.info(
 
                    "HINT: Are you using ORDER BY or comparisons with metadata "
 
                    "that isn't consistently set?\n  "
 
                    "Try looking up that metadata with str_meta() instead to "
 
                    "ensure your comparisons use a consistent data type.",
 
                )
 
            try:
 
                hint_func = getattr(self, f'_hint_{type(error).__name__}')
 
            except AttributeError:
 
                pass
 
            else:
 
                hint_func(error, statement)
 
            return
 

	
 
        if not rows and output_format != 'ods':
 
            print("(empty)", file=self.outfile)
 
        else:
 
            logger.debug("rendering query as %s", output_format)
 
            render_func(statement, row_types, rows)
 

	
 
    def _hint_TypeError(self, error: TypeError, statement: QueryStatement) -> None:
 
        try:
 
            errmsg = str(error.args[0])
 
        except IndexError:
 
            return
 
        if ' not supported between instances ' in errmsg:
 
            logger.info(
 
                "HINT: Are you using ORDER BY or comparisons with metadata "
 
                "that isn't consistently set?\n  "
 
                "Try looking up that metadata with str_meta() instead to "
 
                "ensure your comparisons use a consistent data type.",
 
            )
 
        elif errmsg.startswith('unhashable type: '):
 
            logger.info(
 
                "HINT: bean-query does not support selecting columns or "
 
                "functions that return multiple items as non-aggregate data in "
 
                "GROUP BY queries.\n  "
 
                "If you want to aggregate that data, run it through set().",
 
            )
 

	
 
    def _render_csv(self, statement: QueryStatement, row_types: RowTypes, rows: Rows) -> None:
 
        bc_query_render.render_csv(
 
            row_types,
 
            rows,
 
            self.options_map['dcontext'],
 
            self.outfile,
 
            self.vars['expand'],
 
        )
 

	
 
    def _render_ods(self, statement: QueryStatement, row_types: RowTypes, rows: Rows) -> None:
 
        self.ods.write_query(statement, row_types, rows, self.last_line_parsed)
 
        logger.info(
setup.py
Show inline comments
 
#!/usr/bin/env python3
 

	
 
from setuptools import setup
 

	
 
setup(
 
    name='conservancy_beancount',
 
    description="Plugin, library, and reports for reading Conservancy's books",
 
    version='1.19.3',
 
    version='1.19.4',
 
    author='Software Freedom Conservancy',
 
    author_email='info@sfconservancy.org',
 
    license='GNU AGPLv3+',
 

	
 
    install_requires=[
 
        'babel>=2.6',  # Debian:python3-babel
 
        'beancount>=2.2',  # Debian:beancount
 
        'GitPython>=2.0',  # Debian:python3-git
 
        # 1.4.1 crashes when trying to save some documents.
 
        'odfpy>=1.4.0,!=1.4.1',  # Debian:python3-odf
 
        'pdfminer.six>=20200101',
 
        'python-dateutil>=2.7',  # Debian:python3-dateutil
0 comments (0 inline, 0 general)