Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running where or find query on User model #234

Closed
girardinsamuel opened this issue Nov 1, 2020 · 14 comments
Closed

Error running where or find query on User model #234

girardinsamuel opened this issue Nov 1, 2020 · 14 comments
Labels
bug An existing feature is not working as intended

Comments

@girardinsamuel
Copy link
Contributor

On a test project with masonite-orm v0.8.0b I got an error running User.find(29) or User.where("id", 29) even if this id exists (with postgres, did not test it with other databases).

Masonite Python 3.8.5 Console
This interactive console has the following things imported:
    container as 'app'

Type `exit()` to exit.
>>> from app.User import User
>>> User.all().count()
Running query SELECT * FROM "users" WHERE "users"."deleted_at" IS NULL, (None,). Executed in 0.00ms
1
>>> User.first().id
Running query SELECT * FROM "users" WHERE "users"."deleted_at" IS NULL LIMIT 1, (None,). Executed in 0.00ms
29
>>> User.find(29)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/models/Model.py", line 212, in find
    return cls().where(cls.get_primary_key(), record_id).first()
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/query/QueryBuilder.py", line 1004, in first
    result = self.new_connection().query(
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/PostgresConnection.py", line 158, in query
    raise e
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/PostgresConnection.py", line 150, in query
    self.statement(query, bindings)
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/BaseConnection.py", line 38, in statement
    self._cursor.execute(query, bindings)
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/psycopg2/extras.py", line 251, in execute
    return super(RealDictCursor, self).execute(query, vars)
TypeError: not all arguments converted during string formatting
>>> User.where("id", 29)
<masoniteorm.query.QueryBuilder.QueryBuilder object at 0x106608610>
>>> User.where("id", 29).get()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/query/QueryBuilder.py", line 1158, in get
    result = self.new_connection().query(self.to_qmark(), self._bindings)
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/PostgresConnection.py", line 158, in query
    raise e
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/PostgresConnection.py", line 150, in query
    self.statement(query, bindings)
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/BaseConnection.py", line 38, in statement
    self._cursor.execute(query, bindings)
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/psycopg2/extras.py", line 251, in execute
    return super(RealDictCursor, self).execute(query, vars)
TypeError: not all arguments converted during string formatting
>>> 
@girardinsamuel
Copy link
Contributor Author

girardinsamuel commented Nov 1, 2020

Is it just an issue with the logger trying to log something in console and try to build bad formatted string ?

@girardinsamuel
Copy link
Contributor Author

Same error with any of the fields (not only id):

>>> User.first().email
Running query SELECT * FROM "users" WHERE "users"."deleted_at" IS NULL LIMIT 1, (None,). Executed in 0.00ms
'samuel.girardin5@gmail.com'
>>> User.where("email", 'samuel.girardin5@gmail.com')
<masoniteorm.query.QueryBuilder.QueryBuilder object at 0x1065fa100>
>>> User.where("email", 'samuel.girardin5@gmail.com').get()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/query/QueryBuilder.py", line 1158, in get
    result = self.new_connection().query(self.to_qmark(), self._bindings)
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/PostgresConnection.py", line 158, in query
    raise e
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/PostgresConnection.py", line 150, in query
    self.statement(query, bindings)
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/masoniteorm/connections/BaseConnection.py", line 38, in statement
    self._cursor.execute(query, bindings)
  File "/Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages/psycopg2/extras.py", line 251, in execute
    return super(RealDictCursor, self).execute(query, vars)
TypeError: not all arguments converted during string formatting 

@girardinsamuel
Copy link
Contributor Author

@josephmancuso Some thoughts on this ? Did I misconfigured something or is it a real bug ? I tried to track it down but I did not found the exact line yet

@josephmancuso
Copy link
Member

I guess it's a real bug. I feel like I would have seen it by now though. I'm guessing that error has to do with too many bindings being passed to the connection query method?

@josephmancuso
Copy link
Member

>>> User.where('id', 29).get()
Running query SELECT * FROM "friends" WHERE "friends"."id" = %s, (29,). Executed in 0.18ms
<src.masoniteorm.collection.Collection.Collection object at 0x10ff0dd60>

@josephmancuso
Copy link
Member

I can't reproduce 🤔

@josephmancuso
Copy link
Member

josephmancuso commented Nov 1, 2020

do you have masonite-orm installed maybe? try pip show masonite-orm

@josephmancuso josephmancuso added the bug An existing feature is not working as intended label Nov 1, 2020
@girardinsamuel
Copy link
Contributor Author

Name: masonite-orm
Version: 0.8.0b0
Summary: The Official Masonite ORM
Home-page: https://github.com/masoniteframework/orm
Author: Joe Mancuso
Author-email: joe@masoniteproject.com
License: MIT
Location: /Users/samuel/.virtualenvs/masonite_pingcrm/lib/python3.8/site-packages
Requires: faker, pendulum, cleo, inflection
Required-by: masonite

@girardinsamuel
Copy link
Contributor Author

girardinsamuel commented Nov 1, 2020

I am trying to maintain/complete the ping crm demo for the inertia adapter and as I am doing every 5/6 days, ORM changed, so I always start by updating to the last orm version and it's not always easy for now lol.

@girardinsamuel
Copy link
Contributor Author

the full list of requirements of my test project:

backpack==0.1
bcrypt==3.1.7
blinker==1.4
certifi==2020.6.20
cffi==1.14.2
chardet==3.0.4
cleo==0.8.1
clikit==0.6.2
crashtest==0.3.1
cryptography==2.9
dnspython==2.0.0
exceptionite==1.0.1
Faker==4.1.4
gunicorn==20.0.4
hfilesize==0.1.0
hupper==1.9.1
idna==2.10
inflection==0.3.1
Jinja2==2.11.2
lazy-object-proxy==1.5.1
MarkupSafe==1.1.1
masonite @ file:///Users/samuel/Projets/Web/Masonite/masonite
masonite-dot==0.0.5
masonite-inertia==0.4.0
masonite-js-routes==0.3.0
masonite-logging==1.0.1
masonite-orm==0.8.0b0
masonite-validation==3.0.9
passlib==1.7.2
pastel==0.2.1
pendulum==2.1.2
psutil==5.6.7
psycopg2-binary==2.8.6
pyaml==16.12.2
pycparser==2.20
Pygments==2.7.1
pylev==1.3.0
python-dateutil==2.8.1
python-dotenv==0.10.5
pytz==2020.1
pytzdata==2020.1
PyYAML==5.3.1
requests==2.24.0
requests-file==1.5.1
simplejson==3.17.2
six==1.15.0
tabulate==0.8.7
text-unidecode==1.3
tldextract==2.2.3
tzlocal==1.5.1
urllib3==1.25.10
whitenoise==4.1.4
wrapt==1.12.1

@girardinsamuel
Copy link
Contributor Author

girardinsamuel commented Nov 2, 2020

@josephmancuso

do you have masonite-orm installed maybe? try pip show masonite-orm

I am working on a test project using Masonite 3.0, and I installed the latest masonite-orm version from 0.8 branch. Is it the correct way ?

@josephmancuso josephmancuso added this to To do in Road to Version 1 via automation Nov 25, 2020
@josephmancuso
Copy link
Member

josephmancuso commented Nov 26, 2020

note to self, just waiting on more info on what query and vars is on this line:

return super(RealDictCursor, self).execute(query, vars)

if vars has more bindings than the query has then it should throw that error. So need to make sure that is not the case. If it is the case then it would be an issue with bindings inside the postgresGrammar class

@girardinsamuel
Copy link
Contributor Author

girardinsamuel commented Nov 26, 2020

  • I'll look into this to check what is the content of query and vars when I run into this issue
  • I should also try with latest version of Masonite/Masonite ORM

@josephmancuso
Copy link
Member

I'm gonna close this bug for now. This was an issue a few releases back. Can reopen if this is still an issue

Road to Version 1 automation moved this from To do to Done Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
No open projects
Development

No branches or pull requests

2 participants