veekun / pokedex

more than you ever wanted to know about Pokémon
MIT License
1.44k stars 637 forks source link

CLI Search by name giving error #296

Closed rluzuriaga closed 4 years ago

rluzuriaga commented 4 years ago

Command used:

pokedex search --name Gloom OR pokedex search --name=Gloom OR pokedex search --name gloom

Error:

Connected to database sqlite:////home/rluzuriaga/GitHub/pokedex/pokedex/data/pokedex.sqlite (from default)
Traceback (most recent call last):
  File "/home/rluzuriaga/GitHub/pokedex/bin/pokedex", line 11, in <module>
    load_entry_point('Pokedex', 'console_scripts', 'pokedex')()
  File "/home/rluzuriaga/GitHub/pokedex/pokedex/main.py", line 28, in setuptools_entry
    main(*sys.argv)
  File "/home/rluzuriaga/GitHub/pokedex/pokedex/main.py", line 24, in main
    args.func(parser, args)
  File "/home/rluzuriaga/GitHub/pokedex/pokedex/cli/search.py", line 20, in command_search
    results = search(session, **vars(args))
  File "/home/rluzuriaga/GitHub/pokedex/pokedex/search.py", line 65, in search
    return query.all()
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py", line 3244, in all
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py", line 3403, in __iter__
  File "/home/rluzuriaga/GitHub/pokedex/pokedex/db/multilang.py", line 216, in _execute_and_instances
    return super(MultilangQuery, self)._execute_and_instances(*args, **kwargs)
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py", line 3428, in _execute_and_instances
  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 984, in execute
  File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/elements.py", line 293, in _execute_on_connection
  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1103, in _execute_clauseelement
  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1288, in _execute_context
  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1482, in _handle_dbapi_exception
  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1248, in _execute_context
  File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/default.py", line 588, in do_execute
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 4 - probably unsupported type.
[SQL: SELECT pokemon.id AS pokemon_id, pokemon.identifier AS pokemon_identifier, pokemon.species_id AS pokemon_species_id, pokemon.height AS pokemon_height, pokemon.weight AS pokemon_weight, pokemon.base_experience AS pokemon_base_experience, pokemon."order" AS pokemon_order, pokemon.is_default AS pokemon_is_default, pokemon_forms_1.id AS pokemon_forms_1_id, pokemon_forms_1.identifier AS pokemon_forms_1_identifier, pokemon_forms_1.form_identifier AS pokemon_forms_1_form_identifier, pokemon_forms_1.pokemon_id AS pokemon_forms_1_pokemon_id, pokemon_forms_1.introduced_in_version_group_id AS pokemon_forms_1_introduced_in_version_group_id, pokemon_forms_1.is_default AS pokemon_forms_1_is_default, pokemon_forms_1.is_battle_only AS pokemon_forms_1_is_battle_only, pokemon_forms_1.is_mega AS pokemon_forms_1_is_mega, pokemon_forms_1.form_order AS pokemon_forms_1_form_order, pokemon_forms_1."order" AS pokemon_forms_1_order, pokemon_form_names_1.pokemon_form_id AS pokemon_form_names_1_pokemon_form_id, pokemon_form_names_1.local_language_id AS pokemon_form_names_1_local_language_id, pokemon_form_names_1.form_name AS pokemon_form_names_1_form_name, pokemon_form_names_1.pokemon_name AS
pokemon_form_names_1_pokemon_name, pokemon_forms_2.id AS pokemon_forms_2_id, pokemon_forms_2.identifier AS pokemon_forms_2_identifier, pokemon_forms_2.form_identifier AS pokemon_forms_2_form_identifier, pokemon_forms_2.pokemon_id AS pokemon_forms_2_pokemon_id, pokemon_forms_2.introduced_in_version_group_id AS pokemon_forms_2_introduced_in_version_group_id, pokemon_forms_2.is_default AS pokemon_forms_2_is_default, pokemon_forms_2.is_battle_only AS pokemon_forms_2_is_battle_only, pokemon_forms_2.is_mega AS pokemon_forms_2_is_mega, pokemon_forms_2.form_order AS pokemon_forms_2_form_order, pokemon_forms_2."order" AS pokemon_forms_2_order, pokemon_form_names_2.pokemon_form_id AS pokemon_form_names_2_pokemon_form_id, pokemon_form_names_2.local_language_id AS pokemon_form_names_2_local_language_id, pokemon_form_names_2.form_name AS pokemon_form_names_2_form_name, pokemon_form_names_2.pokemon_name AS pokemon_form_names_2_pokemon_name, pokemon_species_1.id AS pokemon_species_1_id, pokemon_species_1.identifier AS pokemon_species_1_identifier, pokemon_species_1.generation_id AS pokemon_species_1_generation_id, pokemon_species_1.evolves_from_species_id AS pokemon_species_1_evolves_from_species_id, pokemon_species_1.evolution_chain_id AS pokemon_species_1_evolution_chain_id, pokemon_species_1.color_id AS pokemon_species_1_color_id, pokemon_species_1.shape_id AS pokemon_species_1_shape_id, pokemon_species_1.habitat_id AS pokemon_species_1_habitat_id, pokemon_species_1.gender_rate AS pokemon_species_1_gender_rate, pokemon_species_1.capture_rate AS pokemon_species_1_capture_rate, pokemon_species_1.base_happiness AS pokemon_species_1_base_happiness, pokemon_species_1.is_baby AS pokemon_species_1_is_baby, pokemon_species_1.hatch_counter AS pokemon_species_1_hatch_counter,
pokemon_species_1.has_gender_differences AS pokemon_species_1_has_gender_differences, pokemon_species_1.growth_rate_id AS pokemon_species_1_growth_rate_id, pokemon_species_1.forms_switchable AS pokemon_species_1_forms_switchable, pokemon_species_1."order" AS pokemon_species_1_order, pokemon_species_1.conquest_order AS pokemon_species_1_conquest_order, pokemon_species_names_1.pokemon_species_id AS pokemon_species_names_1_pokemon_species_id, pokemon_species_names_1.local_language_id AS pokemon_species_names_1_local_language_id, pokemon_species_names_1.name AS pokemon_species_names_1_name, pokemon_species_names_1.genus AS pokemon_species_names_1_genus, types_1.id AS types_1_id, types_1.identifier AS types_1_identifier, types_1.generation_id AS types_1_generation_id, types_1.damage_class_id AS types_1_damage_class_id, type_names_1.type_id AS type_names_1_type_id, type_names_1.local_language_id AS type_names_1_local_language_id, type_names_1.name AS type_names_1_name
FROM pokemon LEFT OUTER JOIN pokemon_forms AS pokemon_forms_1 ON pokemon.id = pokemon_forms_1.pokemon_id LEFT OUTER JOIN pokemon_form_names AS pokemon_form_names_1 ON pokemon_form_names_1.pokemon_form_id = pokemon_forms_1.id AND pokemon_form_names_1.local_language_id = ? LEFT OUTER JOIN pokemon_forms AS pokemon_forms_2 ON pokemon.id = pokemon_forms_2.pokemon_id AND pokemon_forms_2.is_default = 1 LEFT OUTER JOIN pokemon_form_names AS pokemon_form_names_2 ON pokemon_form_names_2.pokemon_form_id = pokemon_forms_2.id AND pokemon_form_names_2.local_language_id = ? JOIN pokemon_species AS pokemon_species_1 ON pokemon_species_1.id = pokemon.species_id LEFT OUTER JOIN pokemon_species_names AS pokemon_species_names_1 ON pokemon_species_names_1.pokemon_species_id = pokemon_species_1.id AND pokemon_species_names_1.local_language_id= ? JOIN pokemon_types AS pokemon_types_1 ON pokemon.id = pokemon_types_1.pokemon_id JOIN types AS types_1 ON types_1.id = pokemon_types_1.type_id LEFT OUTER JOIN type_names AS type_names_1 ON type_names_1.type_id = types_1.id AND type_names_1.local_language_id = ?
WHERE EXISTS (SELECT 1
FROM pokemon_species
WHERE pokemon_species.id = pokemon.species_id AND lower(?) = ?) ORDER BY pokemon_forms_1."order" ASC, pokemon_forms_1.form_identifier ASC, pokemon_types_1.slot ASC]
[parameters: (9, 9, 9, 9, ColumnAssociationProxyInstance(AssociationProxy('names_local', 'name')), 'gloom')]
(Background on this error at: http://sqlalche.me/e/rvf5)

What I am trying to do:

I'm not sure if I am just doing something wrong or if it actually is broken. I am trying to familiarize myself with this repo because I want to start contributing to it. I started out by doing what is in the Getting Data wiki: https://github.com/veekun/pokedex/wiki/Getting-Data and I didn't have any problems. I've tried other commands like: pokedex lookup gloom just to see if it was an issue of the data not being loaded but i get the right output.

Connected to database sqlite:////home/rluzuriaga/GitHub/pokedex/pokedex/data/pokedex.sqlite (from default)
Opened lookup index /home/rluzuriaga/GitHub/pokedex/pokedex/data/whoosh-index (from default)
Matched:
pokemon_species: Gloom(Gloom in <pokedex.db.tables.Language object (9): en>)

Edit: I just thought to try that SQL query using SQLite Browser opening the sqlite DB in pokedex/data/pokedex.sqlite and it returned 0 rows.

magical commented 4 years ago

Confirmed. I also get an error when running that command.

FWIW, aside from load, dump and reindex, the pokedex CLI doesn't do much and isn't really maintained. (I didn't even know we had a search command!) If everything else works, you're probably fine.

If you want to further check your install, you could try running the tests: run py.test in the project directory. Or py.test --engine your://sql/uri if you aren't using the default database location.

magical commented 4 years ago

Actually... it works for me with an sqlite database and sqlalchemy 0.9.7 or 1.2.5.

When connected to a postgresql database i get a different error than the one you got:

Connected to database postgresql:///pokedex (from command line)
Traceback (most recent call last):
  File "../bin/pokedex", line 9, in 
    load_entry_point('Pokedex==0.1', 'console_scripts', 'pokedex')()
  File "/home/andrew/veekun/pokedex/pokedex/main.py", line 28, in setuptools_entry
    main(*sys.argv)
  File "/home/andrew/veekun/pokedex/pokedex/main.py", line 24, in main
    args.func(parser, args)
  File "/home/andrew/veekun/pokedex/pokedex/cli/search.py", line 20, in command_search
    results = search(session, **vars(args))
  File "/home/andrew/veekun/pokedex/pokedex/search.py", line 65, in search
    return query.all()
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2300, in all
    return list(self)
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2412, in __iter__
    return self._execute_and_instances(context)
  File "/home/andrew/veekun/pokedex/pokedex/db/multilang.py", line 216, in _execute_and_instances
    return super(MultilangQuery, self)._execute_and_instances(*args, **kwargs)
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2427, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 729, in execute
    return meth(self, multiparams, params)
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 321, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 826, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 958, in _execute_context
    context)
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1160, in _handle_dbapi_exception
    exc_info
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 951, in _execute_context
    context)
  File "/home/andrew/veekun/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 436, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) subquery in FROM must have an alias
LINE 4: FROM pokemon_species, (SELECT pokemon_species_names.name AS ...
                              ^
HINT:  For example, FROM (SELECT ...) [AS] foo.
 'SELECT pokemon.id AS pokemon_id, pokemon.identifier AS pokemon_identifier, pokemon.species_id AS pokemon_species_id, pokemon.
height AS pokemon_height, pokemon.weight AS pokemon_weight, pokemon.base_experience AS pokemon_base_experience, pokemon."order"
 AS pokemon_order, pokemon.is_default AS pokemon_is_default, pokemon_forms_1.id AS pokemon_forms_1_id, pokemon_forms_1.identifi
er AS pokemon_forms_1_identifier, pokemon_forms_1.form_identifier AS pokemon_forms_1_form_identifier, pokemon_forms_1.pokemon_i
d AS pokemon_forms_1_pokemon_id, pokemon_forms_1.introduced_in_version_group_id AS pokemon_forms_1_introduced_in_version_group_
id, pokemon_forms_1.is_default AS pokemon_forms_1_is_default, pokemon_forms_1.is_battle_only AS pokemon_forms_1_is_battle_only,
 pokemon_forms_1.is_mega AS pokemon_forms_1_is_mega, pokemon_forms_1.form_order AS pokemon_forms_1_form_order, pokemon_forms_1.
"order" AS pokemon_forms_1_order, pokemon_form_names_1.pokemon_form_id AS pokemon_form_names_1_pokemon_form_id, pokemon_form_na
mes_1.local_language_id AS pokemon_form_names_1_local_language_id, pokemon_form_names_1.form_name AS pokemon_form_names_1_formname, pokemon_form_names_1.pokemon_name AS pokemon_form_names_1_pokemon_name, pokemon_forms_2.id AS pokemon_forms_2_id, pokemon
_forms_2.identifier AS pokemon_forms_2_identifier, pokemon_forms_2.form_identifier AS pokemon_forms_2_form_identifier, pokemon_
forms_2.pokemon_id AS pokemon_forms_2_pokemon_id, pokemon_forms_2.introduced_in_version_group_id AS pokemon_forms_2_introduced_
in_version_group_id, pokemon_forms_2.is_default AS pokemon_forms_2_is_default, pokemon_forms_2.is_battle_only AS pokemon_forms_
2_is_battle_only, pokemon_forms_2.is_mega AS pokemon_forms_2_is_mega, pokemon_forms_2.form_order AS pokemon_forms_2_form_order,
 pokemon_forms_2."order" AS pokemon_forms_2_order, pokemon_form_names_2.pokemon_form_id AS pokemon_form_names_2_pokemon_form_id
, pokemon_form_names_2.local_language_id AS pokemon_form_names_2_local_language_id, pokemon_form_names_2.form_name AS pokemon_f
orm_names_2_form_name, pokemon_form_names_2.pokemon_name AS pokemon_form_names_2_pokemon_name, pokemon_species_1.id AS pokemon_
species_1_id, pokemon_species_1.identifier AS pokemon_species_1_identifier, pokemon_species_1.generation_id AS pokemon_species_
1_generation_id, pokemon_species_1.evolves_from_species_id AS pokemon_species_1_evolves_from_species_id, pokemon_species_1.evol
ution_chain_id AS pokemon_species_1_evolution_chain_id, pokemon_species_1.color_id AS pokemon_species_1_color_id, pokemon_speci
es_1.shape_id AS pokemon_species_1_shape_id, pokemon_species_1.habitat_id AS pokemon_species_1_habitat_id, pokemon_species_1.ge
nder_rate AS pokemon_species_1_gender_rate, pokemon_species_1.capture_rate AS pokemon_species_1_capture_rate, pokemon_species_1
.base_happiness AS pokemon_species_1_base_happiness, pokemon_species_1.is_baby AS pokemon_species_1_is_baby, pokemon_species_1.
hatch_counter AS pokemon_species_1_hatch_counter, pokemon_species_1.has_gender_differences AS pokemon_species_1_has_gender_diff
erences, pokemon_species_1.growth_rate_id AS pokemon_species_1_growth_rate_id, pokemon_species_1.forms_switchable AS pokemon_sp
ecies_1_forms_switchable, pokemon_species_1."order" AS pokemon_species_1_order, pokemon_species_1.conquest_order AS pokemon_spe
cies_1_conquest_order, pokemon_species_names_1.pokemon_species_id AS pokemon_species_names_1_pokemon_species_id, pokemon_specie
s_names_1.local_language_id AS pokemon_species_names_1_local_language_id, pokemon_species_names_1.name AS pokemon_species_names
_1_name, pokemon_species_names_1.genus AS pokemon_species_names_1_genus, types_1.id AS types_1_id, types_1.identifier AS types_
1_identifier, types_1.generation_id AS types_1_generation_id, types_1.damage_class_id AS types_1_damage_class_id, type_names_1.
type_id AS type_names_1_type_id, type_names_1.local_language_id AS type_names_1_local_language_id, type_names_1.name AS type_na
mes_1_name \nFROM pokemon LEFT OUTER JOIN pokemon_forms AS pokemon_forms_1 ON pokemon.id = pokemon_forms_1.pokemon_id LEFT OUTE
R JOIN pokemon_form_names AS pokemon_form_names_1 ON pokemon_form_names_1.pokemon_form_id = pokemon_forms_1.id AND pokemon_form
_names_1.local_language_id = %(_default_language_id)s LEFT OUTER JOIN pokemon_forms AS pokemon_forms_2 ON pokemon.id = pokemon_
forms_2.pokemon_id AND pokemon_forms_2.is_default = true LEFT OUTER JOIN pokemon_form_names AS pokemon_form_names_2 ON pokemon_
form_names_2.pokemon_form_id = pokemon_forms_2.id AND pokemon_form_names_2.local_language_id = %(_default_language_id)s JOIN po
kemon_species AS pokemon_species_1 ON pokemon_species_1.id = pokemon.species_id LEFT OUTER JOIN pokemon_species_names AS pokemo
n_species_names_1 ON pokemon_species_names_1.pokemon_species_id = pokemon_species_1.id AND pokemon_species_names_1.local_langua
ge_id = %(_default_language_id)s JOIN pokemon_types AS pokemon_types_1 ON pokemon.id = pokemon_types_1.pokemon_id JOIN types AS
 types_1 ON types_1.id = pokemon_types_1.type_id LEFT OUTER JOIN type_names AS type_names_1 ON type_names_1.type_id = types_1.i
d AND type_names_1.local_language_id = %(_default_language_id)s \nWHERE EXISTS (SELECT 1 \nFROM pokemon_species, (SELECT pokemo
n_species_names.name AS name \nFROM pokemon_species_names, pokemon_species \nWHERE pokemon_species_names.pokemon_species_id = p
okemon_species.id AND pokemon_species_names.local_language_id = %(_default_language_id)s) \nWHERE pokemon_species.id = pokemon.
species_id AND lower((SELECT pokemon_species_names.name \nFROM pokemon_species_names \nWHERE pokemon_species_names.pokemon_spec
ies_id = pokemon_species.id AND pokemon_species_names.local_language_id = %(_default_language_id)s)) = %(lower_1)s) ORDER BY po
kemon_forms_1."order" ASC, pokemon_forms_1.form_identifier ASC, pokemon_types_1.slot ASC' {'lower_1': 'gloom', '_default_langua
ge_id': 9}

What version of SQLAlchemy are you using?

rluzuriaga commented 4 years ago

I'm using SQLAlchemy 1.3.15 I'll try downgrading to 1.2.5 and check.

rluzuriaga commented 4 years ago

Downgraded to 1.2.5 and search is not working. Maybe changing the setup.py to specify SQLAlchemy to 1.2.5 so that the setup doesn't install the newest version that doesn't work 100%?