datastax/python-driver — pull request #40 by Kami (2013-09-22 20:34:51+00:00)
Title: Allow user to specify consistency level with prepared statements

Currently you can't specify a consistency level when using a `PreparedStatement`. I'm not sure if this is by design or it's a bug. Looking at the code makes it seems like it's a bug / an oversight though.

With this pull request user can pass `consistency_level` argument to the `session.bind` method. `PreparedStatament` works slightly different than `SimpleStatement` so I wasn't sure of the best place to put it, but `session.bind` seems like decent place.

There are a couple of other things which I don't like that much:

1. Currently `BoundStatement` inherits from the `Statement` class. When creating a new instance of `BoundStatament`, you need to pass `PreparedStatement` instance and you can also pass all the other arguments which are handled in the parent class (`Statement`). This other arguments include `consistency_level`.

Before my pull request, `BoundStatement` was setting consistency_level to `prepared.consistency_level`, but later overwriting it with `None` with a call to the parent constructor. This meant that `prepared.consistency_level` would be unused if specified (which it wasn't).

In this pull request I've changed it to call parent constructor before the consistency level assignment. This means that `prepared.consistency_level` always takes precedence over `consistency_level` argument passed to the constructor.

I still don't like this approach because it means that `consistency_level` which can get passed to the `BoundStatement` constructor is unused and useless.

We have a couple of options here:

1. Remove *args and **kwargs and explicitly declare which parent class arguments are supported (exclude `consistency_level` from this list)
2. Remove consistency_level from PreparedStatement and require user to pass it to `BoundStatament` constructor

Note: This is not a finished pull request yet. I will add tests and finish it once we all agree on approach we want to take.

Comments and feedback is welcome.