Repository navigation
Replies: 11 comments
|
@Skelmis Yes, Piccolo will raise a piccolo/piccolo/query/methods/create_index.py Lines 66 to 68 in 11ada0b If we replace method_name = self.method.value
if method_name != "btree":
method_name = self.method.value
colored_warning(
message=(
"=> A btree index was not used when creating the table. "
"Piccolo converts the index method to a btree because "
"it is only method supported by SQLite."
),
level=Level.high,
)the engine will replace the index name of the created table with the default one. Should we do this or not? |
|
I would quite like it, but it should probably raise a warning so that people do actually know that it's happening as well as being documented behaviour |
|
@dantownsend what do you think about this change? |
|
Hmm, yeah - tricky. I wish SQLite was closer to Postgres in terms of functionality. The easiest solution is to use Postgres for unit tests too. That's what I typically do. We could have some kind of If we just change the index method during tests, then our code needs to be aware of when it's running in a test or not. |
@dantownsend I absolutely agree that it is best to have
I think this change is sufficient (I may be wrong, but I don't see any potential problems) because it just replaces |
|
Yes, I see your point. It's not clear to me if it's better to raise an exception, or just fall back to a supported index type. I wonder what happens if SQLite supports What about giving the user an option to explicitly define a fallback? class MyTable(Table):
my_column = Varchar(index_method=[Index.hash, Index.btree])The first one gets applied if possible, and it falls back to ones lower in the list depending on the database. |
You are right. I hadn't thought about it.
That's a good option, but it seems complicated to me for a case that will probably be rare. I think in that case we need to change the migrations as well because |
|
Is the migration engine not aware of the database, I thought it was. But yea I've had heaps of issues running postgres for tests with asyncpg causing a bunch of issues based on event loop shenanigans where as sqlite just works. Would perhaps adding an extra column argument of like |
|
I've never had any problems testing in |
Original PostHeres what brings this on for me:
import os
from dotenv import load_dotenv
from piccolo.conf.apps import AppRegistry
from piccolo.engine import SQLiteEngine, PostgresEngine
load_dotenv()
DB = PostgresEngine(
config={
"database": "tests",
"user": os.environ["POSTGRES_USER"],
"password": os.environ["POSTGRES_PASSWORD"],
"host": os.environ["POSTGRES_HOST"],
"port": int(os.environ["POSTGRES_PORT"]),
},
)
# DB = SQLiteEngine(path="test_suite.sqlite")
APP_REGISTRY = AppRegistry(
apps=[
"home.piccolo_app",
"piccolo_admin.piccolo_app",
"piccolo_api.mfa.authenticator.piccolo_app",
]
)I then have this in my conftest file which is coupled together from various areas @pytest.fixture(scope="function", autouse=True)
async def configure_testing():
# Setup DB per test
with set_env_var(var_name="PICCOLO_CONF", temp_value="piccolo_conf_test"):
from app import app
app.debug = True
refresh_db()
tables = Finder().get_table_classes()
# Ensure DB is cleared from any prior hanging tests
await drop_db_tables(*tables)
# Set up DB
await create_db_tables(*tables)
await scaffold_db()
yield
await drop_db_tables(*tables)But my issue is that I keep getting errors like this So in classic 'now I am sharing it I've fixed it', I've got my test cases working with postgres by removing the yield from the original post. I would still be keen for a way to have sqlite not just error with unsupported hash types though.
I think this could perhaps be good? We could still check it, and if its not btree just inform the user that we have changed it to btree and maybe link them to this issue |
Uh oh!
There was an error while loading. Please reload this page.
Currently I run various text columns with indexes on them, ideally
IndexMethod.hashas this provides good equality matching lookups. I run into an issue with this however during tests which run on sqlite, as Piccolo will exit with an error if this index method is used. This is really not ideal and basically means I cannot use this index method at all as it is not feasible to run postgres just for test cases.Possible I'm thinking of maybe adding another way to say to Piccolo, hey please map this to a usable sqlite index instead of erroring, either by app level variable of a column argument like
sqlite_index_method. I.e. In my use case it is fine forIndexMethod.hashto be mapped toIndexMethod.btreeif the DB is sqlite, as longI also may be overlooking something, perhaps there is a way to do this already?
Thoughts?
All reactions