-
Notifications
You must be signed in to change notification settings - Fork 46
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
api: native crud module support #264
api: native crud module support #264
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your draft! The task it much trickier that I initially have expected. I gave it some thought (and recalled some crud
behavior) and I think that we should try to rework some things. I'll summarize my comments here.
- Try to get rid of class
Crud
. - Try to work with
call
s only. - Do not expose configuration handles.
- Raise errors as exceptions.
- Optimize utils usage.
I see that the first one is a requirement to be able to use conn.crud.method
, but is such approach really widespread in Python? I'm not well-experienced myself, but I think that I have seen providing many handles from a single place more often than using complex hierarchy. Maybe it's worth to study this question a little by using some Python modules as an example (and if you still decide to use conn.crud.method
, maybe you'll see some nice implementation approaches).
It is highly likely that I have forgot to mention something important in this review, so feel free to ask me any additional questions here or in personal chat.
ad145c4
to
6343199
Compare
Thank you for your feedback! I have made most of the edits (with the exception of the |
I don't get this comment. |
I mean, in exc_crud.res, the result can only appear when the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I think current API is fine and we may continue to work with it.
3ed26c5
to
cc04dc4
Compare
Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the update!
See comments below. The main drawback of the current version is that tests are actually not run on CI, so I think you would be interested to fix it first and then fix everything that fails on CI.
There are some things that maybe are not covered yet, but there should be enough work for now.
20f6c01
to
da98380
Compare
b5de7af
to
1611fc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long response. I've thought that error is less trickier, I've proposed the solution.
tarantool/error.py
Outdated
self.errs = args[1] | ||
else: | ||
# Sets tarantool.crud.CrudError object. | ||
self.err = args[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already an exception API in the connector. Receiving a different types of exceptions may be confusing, especially if they uses the same fields with different meanings.
tarantool/error.py
Outdated
self.errs = args[1] | ||
else: | ||
# Sets tarantool.crud.CrudError object. | ||
self.err = args[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example
>>> c.select('myspace')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/georgymoiseev/Development/github/tarantool/tarantool-python/tarantool/connection.py", line 1873, in select
space_name = self.schema.get_space(space_name).sid
File "/home/georgymoiseev/Development/github/tarantool/tarantool-python/tarantool/schema.py", line 216, in get_space
return self.fetch_space(space)
File "/home/georgymoiseev/Development/github/tarantool/tarantool-python/tarantool/schema.py", line 243, in fetch_space
raise SchemaError(errmsg)
tarantool.error.SchemaError: There's no space with name 'myspace'
>>> c.crud_select('myspace')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/georgymoiseev/Development/github/tarantool/tarantool-python/tarantool/connection.py", line 2550, in crud_select
raise CrudModuleError(None, CrudError(crud_resp[1]))
tarantool.error.CrudModuleError: (None, <tarantool.crud.CrudError object at 0x7f4864a525f0>)
tarantool/crud.py
Outdated
info = ". Ensure that you're calling crud.router and user has sufficient grants" | ||
e.message = e.message + info | ||
e.extra_info.message = e.extra_info.message + info | ||
e.args = (e.args[0], e.args[1] + info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second, let's never mess with args
.
>>> class MyError(Exception):
... def __init__(self, *args):
... pass
...
>>> MyError(1, 2)
MyError(1, 2)
>>> e = MyError(1, 2)
>>> e.
e.args e.with_traceback(
>>> e.args
(1, 2)
args
exception attribute is essentially a copy of "what data was used to raise exception with".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either you forgot to commit it or lost it while doing other reworks, but it's still in call_crud
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, deleted
1611fc9
to
3455edc
Compare
tarantool/error.py
Outdated
.. _crud: https://github.com/tarantool/crud | ||
""" | ||
|
||
def __init__(self, *args): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are always two positional arguments, why use *args
instead of def __init__(self, success, error):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, now using __init__(self, success, error):
tarantool/error.py
Outdated
""" | ||
|
||
# Sets tarantool.crud.CrudResult object. | ||
self.success = args[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no success other than nil
for non-many requests, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, deleted
tarantool/error.py
Outdated
self.errs = args[1] | ||
else: | ||
# Sets tarantool.crud.CrudError object. | ||
self.err = args[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not yet done: CrudModuleError
inherits DatabaseError, but it never calls its __init__
(like here:
tarantool-python/tarantool/error.py
Line 262 in 1154b3d
super(NetworkError, self).__init__(0, self.message) |
tarantool/error.py
Outdated
self.errs = args[1] | ||
else: | ||
# Sets tarantool.crud.CrudError object. | ||
self.err = args[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same about CrudModuleManyError
tarantool/crud.py
Outdated
""" | ||
|
||
|
||
def wrapCrudUndefinedProcedureError(e: DatabaseError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no wrapCrudUndefinedProcedureError
now, but there is also no exceptions chaining yet and you still overwrite exception fields.
tarantool/crud.py
Outdated
info = ". Ensure that you're calling crud.router and user has sufficient grants" | ||
e.message = e.message + info | ||
e.extra_info.message = e.extra_info.message + info | ||
e.args = (e.args[0], e.args[1] + info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either you forgot to commit it or lost it while doing other reworks, but it's still in call_crud
tarantool/connection_pool.py
Outdated
|
||
def crud_insert(self, space_name, values, opts={}, *, mode=Mode.ANY): | ||
""" | ||
Execute an CRUD_INSERT request on the pool server: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SUCH_STYLE
in other documentation strings refer to IPROTO_REQUEST
codes (omitting the IPROTO_
part), so writing CRUD_INSERT
here and below may be a bit confusing.
You may ignore this comment if you wish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, rewritten without uppercase
3455edc
to
2e88041
Compare
Thank you for your feedback! I have updated the PR description and tried to answer all the comments on the code review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your updates! Let's resolve a couple of minor comments and I'll merge this one.
Adds native api support for crud module [1] to use it from a connection object. 1. github.com/tarantool/crud Closes #205
2e88041
to
832ab10
Compare
Docker debian/ubuntu images are sudoless. Follows #264
Set valid package manager for fedora. Fix using apt for docker: debian/ubuntu containers are sudoless. Follows #264
Set valid package manager for fedora. Fix using apt for docker: debian/ubuntu containers are sudoless. Follows #264
Set valid package manager for fedora. Fix using apt for docker: debian/ubuntu containers are sudoless. Follows #264
Set valid package manager for fedora. Fix using apt for docker: debian/ubuntu containers are sudoless. Follows #264
Set valid package manager for fedora. Fix using apt for docker: debian/ubuntu containers are sudoless. Follows #264
Set valid package manager for fedora. Fix using apt for docker: debian/ubuntu containers are sudoless. Follows #264
tarantool-python static analysis was introduced in [1], CRUD API was introduced in [2]. 1. tarantool/tarantool-python#289 2. tarantool/tarantool-python#264
tarantool-python static analysis was introduced in [1], CRUD API was introduced in [2]. 1. tarantool/tarantool-python#289 2. tarantool/tarantool-python#264
* connectors: remove queue-python tarantool/queue-python [1] last commit was in 2016. Module does not support Tarantool 1.6+. 1. https://github.com/tarantool/queue-python * connectors: update aiotarantool status shveenkov/aiotarantool last commit was in 2019. 1. https://github.com/shveenkov/aiotarantool * connectors: remove gtarantool from comparison shveenkov/gtarantool [1] last commit was in 2016. It is useless for modern Tarantool users. 1. https://github.com/shveenkov/gtarantool * connectors: update comparison table tarantool-python static analysis was introduced in [1], CRUD API was introduced in [2]. 1. tarantool/tarantool-python#289 2. tarantool/tarantool-python#264
Adds native api support for crud module to use it from a connection object.
Below there are examples of using the api.
Inserting data via crud:
Crud not found on the router:
Select and unflatten_rows via crud:
Truncate and len via crud:
Encoding=None in Connection:
Closes #205