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

Remove obsolete loop._selector #659

Closed
wants to merge 1 commit into from

Conversation

wankata
Copy link

@wankata wankata commented Mar 6, 2021

Description

Remove obsolete loop._selector from contrib/test

Motivation and Context

The loop._selector was introduced in commit 40f4945 with the ability to provide loop to the initializer. At that point, the loop was BaseSelectorEventLoop, which has a private _selector property.

In 743795d the BaseSelectorEventLoop was replaced by AbstractEventLoop, but the _selector artefact remains.

The problem can be easily identified, when you use uvloop, which implements AbstractEventLoop and is not a SelectorEventLoop.

Resolves: #532
See also: #533

How Has This Been Tested?

I've tested it manually with an uvloop.Loop and it seems to work properly.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

The loop._selector was introduced in commit 40f4945 with the ability to
provide loop to the initializer. At that point, the loop was
BaseSelectorEventLoop, which has a private _selector property.

In 743795d the BaseSelectorEventLoop was replaced by AbstractEventLoop,
but the _selector artefact remains.

The problem can be easily identified, when you use uvloop, which
implements AbstractEventLoop and is not a SelectorEventLoop.

Resolves: tortoise#532
See also: tortoise#533
@wankata wankata marked this pull request as ready for review March 6, 2021 09:23
@wankata
Copy link
Author

wankata commented Mar 12, 2021

Could someone with admin rights on the repo, rerun the checks? The CI stalled for some reason, but I am pretty sure, that they should all pass.

@long2ice
Copy link
Member

OK

@wankata
Copy link
Author

wankata commented Mar 12, 2021

Thanks. This is strange, it is hanging again...

@long2ice
Copy link
Member

Did you run make style ci in local?

@wankata
Copy link
Author

wankata commented Mar 12, 2021

I was just running the make commands as you answered.

It fails on master, develop and of course on my branch with the same issue:
mypy tortoise/ examples/ tests/ conftest.py
Found 19 errors in 7 files (checked 196 source files)
Most of the errors are like:

examples/fastapi/main.py:43: error: Untyped decorator makes function "delete_user" untyped
    @app.delete("/user/{user_id}", response_model=Status, responses={404: {"model": HTTPNotFoundError}})

But this should emit an error in the ci and not make it hang.

@long2ice
Copy link
Member

You can merge develop branch first

@wankata
Copy link
Author

wankata commented Mar 21, 2021

You can merge develop branch first

What do you mean? I've ran the tests on the develop branch directly. They fail there the exact same way. I've updated my develop from the upstream repo to it's latest state too, and nothing changed.

I would tell, that something in my environment is odd, if you cannot reproduce it, but why the CI is failing although then?
Another interesting question is why the CI just hangs without any errors, but I am failing with typing errors...

And all this to just remove 4 obsolete lines of code :)

@stuaxo
Copy link

stuaxo commented May 11, 2023

I've tested this patch locally and it means I can use from tortoise.contrib.test import finalizer, initializer without hitting an exception because _selector doesn't exist any more.

@stuaxo
Copy link

stuaxo commented May 11, 2023

Running the tests locally pass using python 3.10.6, I haven't tried earlier versions.

❯ make test
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: tortoise-orm (0.19.3)
PYTHONDEVMODE=1 TORTOISE_TEST_DB=sqlite://:memory: pytest -n auto --cov=tortoise --tb=native -q
bringing up nodes...
...................s...............................................................................s........................................................................................................................s............................................................................. [ 26%]
..................................................................................................................................s......................s...s.....sssssss.....s.......s..........s.........s.........s....................s.s...s.s.ss............................x..............x....... [ 52%]
s.......x.s...x.s............................................s..........................................................s.......................................................................................................................s.....s...................s............................... [ 78%]
..........s.....s......s.......s.................s...............s.......s...................s.................s........s.....s....s..........s.ss.s...s.sss.sssssss.ssss........ss...............................................................                                                         [100%]
================================================================================================================================================ warnings summary ================================================================================================================================================
tests/test_filtering.py::TestFiltering::test_filter_by_aggregation_field
tests/test_model_methods.py::TestModelMethods::test_str
tests/test_aggregation.py::TestAggregation::test_aggregation
tests/test_filters.py::TestCharFieldFilters::test_endswith
tests/test_model_methods.py::TestModelCreate::test_clone_pk_required_error
tests/test_filters.py::TestCharFkFieldFilters::test_lte
tests/test_model_methods.py::TestModelConstructor::test_m2m
tests/test_concurrency.py::TestConcurrencyIsolated::test_concurrency_transactions_concurrent
  /home/stu/projects/external/libraries/orm/tortoise-orm/tortoise/contrib/test/__init__.py:107: DeprecationWarning: There is no current event loop
    loop = loop or asyncio.get_event_loop()

tests/test_filtering.py: 35 warnings
tests/test_model_methods.py: 77 warnings
tests/test_aggregation.py: 7 warnings
tests/test_filters.py: 43 warnings
tests/test_basic.py: 1 warning
tests/test_bulk.py: 14 warnings
tests/test_only.py: 14 warnings
tests/test_fuzz.py: 1 warning
tests/test_group_by.py: 20 warnings
tests/test_order_by.py: 12 warnings
tests/test_order_by_nested.py: 1 warning
tests/test_prefetching.py: 13 warnings
tests/test_case_when.py: 10 warnings
tests/test_queryset.py: 54 warnings
tests/test_source_field.py: 58 warnings
tests/test_relations.py: 35 warnings
tests/test_concurrency.py: 10 warnings
tests/test_primary_key.py: 8 warnings
tests/test_inheritance.py: 1 warning
tests/test_manager.py: 1 warning
tests/test_transactions.py: 17 warnings
tests/test_manual_sql.py: 5 warnings
tests/test_q.py: 19 warnings
tests/test_update.py: 11 warnings
tests/test_connection.py: 24 warnings
tests/test_validators.py: 7 warnings
tests/backends/test_connection_params.py: 3 warnings
tests/backends/test_db_url.py: 25 warnings
tests/test_default.py: 1 warning
tests/test_early_init.py: 1 warning
tests/test_values.py: 20 warnings
tests/backends/test_postgres.py: 4 warnings
tests/backends/test_explain.py: 1 warning
tests/backends/test_mysql.py: 3 warnings
tests/backends/test_reconnect.py: 2 warnings
tests/contrib/test_pydantic.py: 24 warnings
tests/contrib/test_functions.py: 4 warnings
tests/test_two_databases.py: 4 warnings
tests/contrib/test_tester.py: 6 warnings
tests/fields/test_array.py: 5 warnings
tests/test_relations_with_unique.py: 1 warning
tests/fields/test_binary.py: 6 warnings
tests/test_signals.py: 3 warnings
tests/test_unique_together.py: 2 warnings
tests/backends/test_capabilities.py: 8 warnings
tests/fields/test_decimal.py: 20 warnings
tests/fields/test_bool.py: 5 warnings
tests/fields/test_char.py: 8 warnings
tests/fields/test_fk.py: 32 warnings
tests/fields/test_enum.py: 20 warnings
tests/fields/test_fk_uuid.py: 76 warnings
tests/fields/test_common.py: 5 warnings
tests/fields/test_fk_with_unique.py: 31 warnings
tests/fields/test_float.py: 8 warnings
tests/fields/test_int.py: 21 warnings
tests/fields/test_m2m.py: 12 warnings
tests/fields/test_m2m_uuid.py: 26 warnings
tests/fields/test_json.py: 20 warnings
tests/fields/test_o2o_with_unique.py: 14 warnings
tests/fields/test_subclass.py: 8 warnings
tests/fields/test_text.py: 7 warnings
tests/fields/test_subclass_filters.py: 6 warnings
tests/fields/test_time.py: 36 warnings
tests/model_setup/test_bad_relation_reference.py: 9 warnings
tests/fields/test_uuid.py: 4 warnings
tests/model_setup/test_init.py: 24 warnings
tests/model_setup/test__models__.py: 2 warnings
tests/schema/test_generate_schema.py: 93 warnings
tests/utils/test_describe_model.py: 16 warnings
tests/utils/test_run_async.py: 2 warnings
  /home/stu/projects/external/libraries/orm/tortoise-orm/tortoise/contrib/test/__init__.py:172: DeprecationWarning: There is no current event loop
    loop = asyncio.get_event_loop()

tests/utils/test_run_async.py::TestRunAsync::test_run_async
tests/utils/test_run_async.py::TestRunAsync::test_run_async_raised
  /home/stu/projects/external/libraries/orm/tortoise-orm/tortoise/__init__.py:686: DeprecationWarning: There is no current event loop
    loop = asyncio.get_event_loop()

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

---------- coverage: platform linux, python 3.10.6-final-0 -----------
Name                                                  Stmts   Miss Branch BrPart  Cover   Missing
-------------------------------------------------------------------------------------------------
tortoise/__init__.py                                    319     14    140      3    95%   45, 350, 408, 590-599, 615-616, 622->621
tortoise/backends/__init__.py                             0      0      0      0   100%
tortoise/backends/asyncpg/__init__.py                     2      0      0      0   100%
tortoise/backends/asyncpg/client.py                     125     75     30      2    36%   41, 44, 61-62, 68-69, 72-78, 81-86, 91-95, 98, 101, 105-108, 112-123, 129-144, 148-152, 157-164, 167, 170, 174-177, 181-182, 185-188, 191-194
tortoise/backends/asyncpg/executor.py                     7      1      0      0    86%   13
tortoise/backends/asyncpg/schema_generator.py             5      0      0      0   100%
tortoise/backends/base/__init__.py                        0      0      0      0   100%
tortoise/backends/base/client.py                        144     34     36      4    69%   238-239, 252->256, 264-265, 268-272, 275-284, 292->exit, 295->exit, 301-302, 305-310, 316-318, 321-323, 326-329, 333
tortoise/backends/base/config_generator.py               54      0     24      0   100%
tortoise/backends/base/executor.py                      302     16    168      4    92%   242-264, 467-469, 471->474, 475, 585
tortoise/backends/base/schema_generator.py              169      3     62      0    99%   90, 213-214
tortoise/backends/base_postgres/__init__.py               0      0      0      0   100%
tortoise/backends/base_postgres/client.py                95     23      2      0    74%   89, 93, 97, 101, 105, 108-109, 112-114, 117-121, 124, 128, 132, 136, 142, 146, 150-152
tortoise/backends/base_postgres/executor.py              33     15     12      0    40%   20, 34, 39-50, 53-57
tortoise/backends/base_postgres/schema_generator.py      39      0      6      0   100%
tortoise/backends/mssql/__init__.py                       2      0      0      0   100%
tortoise/backends/mssql/client.py                        28     11      4      0    53%   37-38, 41, 45-50, 55-56
tortoise/backends/mssql/executor.py                      14      4      2      0    62%   14-16, 25
tortoise/backends/mssql/schema_generator.py              45     24      8      0    40%   31-33, 36, 39, 42, 52-57, 60, 63, 66, 77-88, 100-102
tortoise/backends/mysql/__init__.py                       2      0      0      0   100%
tortoise/backends/mysql/client.py                       173     96     52      2    38%   9-12, 43-54, 101, 117-127, 129-130, 133-135, 138-142, 145-146, 149-151, 154-159, 162, 165, 169-173, 177-190, 196-204, 207, 211-214, 219-226, 229, 232, 236-239, 243-244, 247-250, 253-256
tortoise/backends/mysql/executor.py                      42     16      2      0    59%   39-41, 45, 49, 55, 61, 67, 71, 79, 87, 95, 115, 118-123
tortoise/backends/mysql/schema_generator.py              50      0     10      0   100%
tortoise/backends/odbc/__init__.py                        0      0      0      0   100%
tortoise/backends/odbc/client.py                        140     99     38      0    24%   32-44, 56-69, 72-89, 92-94, 97-99, 102-104, 107-111, 114, 118-127, 133-149, 152, 156-159, 164-172, 175, 178, 182-185, 188-189, 192-196, 199-203
tortoise/backends/odbc/executor.py                       11      4      2      0    54%   10, 13-18
tortoise/backends/oracle/__init__.py                      2      0      0      0   100%
tortoise/backends/oracle/client.py                       76     45     16      0    34%   48-54, 57, 60, 63-66, 69-75, 79-85, 89-92, 97-100, 103-114, 119-120
tortoise/backends/oracle/executor.py                     13      9      0      0    31%   7-17
tortoise/backends/oracle/schema_generator.py             63     37     12      0    35%   34-37, 40, 44-46, 49-53, 56-61, 64-68, 78-83, 86, 89, 92, 103-116
tortoise/backends/psycopg/__init__.py                     2      0      0      0   100%
tortoise/backends/psycopg/client.py                     139     73     30      3    43%   25, 28, 41, 49->55, 51, 82-83, 88, 91-92, 97-101, 106-115, 125-142, 147-148, 151-153, 156-160, 165-177, 182, 185, 192-198, 201, 204, 210, 213-218, 221-226
tortoise/backends/psycopg/executor.py                    17      9      8      0    32%   15-25, 28
tortoise/backends/psycopg/schema_generator.py             6      0      0      0   100%
tortoise/backends/sqlite/__init__.py                      2      0      0      0   100%
tortoise/backends/sqlite/client.py                      133      3     30      0    97%   103-105
tortoise/backends/sqlite/executor.py                     46      9     18      0    77%   61-73
tortoise/backends/sqlite/schema_generator.py             22      0      0      0   100%
tortoise/connection.py                                   91      2     24      1    97%   12-14
tortoise/contrib/__init__.py                              0      0      0      0   100%
tortoise/contrib/aiohttp/__init__.py                     17     17      2      0     0%   1-92
tortoise/contrib/blacksheep/__init__.py                  27     27      4      0     0%   1-108
tortoise/contrib/fastapi/__init__.py                     29     29      4      0     0%   1-112
tortoise/contrib/mysql/__init__.py                        0      0      0      0   100%
tortoise/contrib/mysql/fields.py                          3      0      0      0   100%
tortoise/contrib/mysql/functions.py                       6      2      0      0    67%   14-15
tortoise/contrib/mysql/indexes.py                        11      0      2      1    92%   19->exit
tortoise/contrib/mysql/json_functions.py                 55     33     18      0    30%   15, 20-21, 25-28, 31-35, 39, 43-50, 54-57, 61, 72-74, 78-85
tortoise/contrib/mysql/search.py                         27      7      2      0    69%   23, 28-29, 32-34, 43
tortoise/contrib/postgres/__init__.py                     0      0      0      0   100%
tortoise/contrib/postgres/fields.py                      11      0      0      0   100%
tortoise/contrib/postgres/functions.py                   10      3      0      0    70%   10, 19, 30
tortoise/contrib/postgres/indexes.py                     26      0      4      0   100%
tortoise/contrib/postgres/json_functions.py              35     22     10      0    29%   12, 16, 27-33, 39-45, 51-53, 57-64
tortoise/contrib/postgres/search.py                       8      1      0      0    88%   13
tortoise/contrib/pydantic/__init__.py                     4      0      0      0   100%
tortoise/contrib/pydantic/base.py                        45      4     18      0    90%   99-100, 112-113
tortoise/contrib/pydantic/creator.py                    180      0     88      2    99%   412->416, 428->433
tortoise/contrib/pydantic/utils.py                        6      0      0      0   100%
tortoise/contrib/pylint/__init__.py                      66     66     38      0     0%   4-136
tortoise/contrib/quart/__init__.py                       29     29      2      0     0%   1-110
tortoise/contrib/sanic/__init__.py                       17     17      2      0     0%   1-91
tortoise/contrib/sqlite/__init__.py                       0      0      0      0   100%
tortoise/contrib/sqlite/functions.py                      4      0      0      0   100%
tortoise/contrib/starlette/__init__.py                   17     17      2      0     0%   1-91
tortoise/contrib/test/__init__.py                       158      5     34      5    95%   281, 286, 289, 302, 328
tortoise/contrib/test/condition.py                       23      2      0      0    91%   14, 36
tortoise/converters.py                                   83     40     20      0    44%   29-44, 48-52, 56-60, 64, 84, 96-103, 107-111, 124, 128-132
tortoise/exceptions.py                                   14      0      0      0   100%
tortoise/expressions.py                                 319      8    131     10    96%   55->90, 72->79, 74, 122, 230, 449, 475->477, 546, 548, 554, 594
tortoise/fields/__init__.py                               4      0      0      0   100%
tortoise/fields/base.py                                 136     13     41      2    92%   146-163, 184
tortoise/fields/data.py                                 387     32    104      5    88%   218, 360, 378-380, 383-389, 443, 449-457, 465-484, 756
tortoise/fields/relational.py                           222     14     46      1    94%   291-305, 422, 434, 497, 509
tortoise/filters.py                                     108     14     20      0    89%   71, 120, 154, 158, 162, 166, 170, 174, 178, 182, 186, 191, 196, 201
tortoise/functions.py                                    28      0      0      0   100%
tortoise/indexes.py                                      34     13     16      5    56%   6-7, 32, 34, 54-55, 65, 78-83
tortoise/log.py                                           3      0      0      0   100%
tortoise/manager.py                                       8      0      0      0   100%
tortoise/models.py                                      608     10    244     13    97%   262, 286, 631->630, 633->630, 766-767, 843, 845->exit, 1015, 1054->1056, 1102->1104, 1387, 1390, 1401, 1406
tortoise/query_utils.py                                  77      2     24      3    95%   92, 142, 191->193
tortoise/queryset.py                                    876     71    358     33    90%   106, 221, 363, 365, 471-476, 725, 730, 757, 820-825, 831-836, 861->863, 883, 907, 911, 941->943, 957->959, 975, 991-992, 994-995, 1205-1206, 1208-1209, 1266-1267, 1269-1270, 1301, 1304, 1357, 1377, 1480-1481, 1483-1484, 1490, 1494, 1503-1504, 1605-1606, 1608-1609, 1615, 1619, 1628-1629, 1678, 1709-1710, 1752-1753, 1798->1805, 1850, 1855-1858
tortoise/router.py                                       29      8      8      2    68%   7, 19-27
tortoise/signals.py                                      27      0      8      0   100%
tortoise/timezone.py                                     37     11     12      4    61%   27, 54, 57, 71, 98-101, 110-113
tortoise/transactions.py                                 25      0      6      0   100%
tortoise/utils.py                                        17      0      6      0   100%
tortoise/validators.py                                   75     16     22      4    75%   55, 58-61, 71, 76, 89, 94, 147-153
-------------------------------------------------------------------------------------------------
TOTAL                                                  6344   1155   2032    109    80%

1067 passed, 65 skipped, 4 xfailed, 1136 warnings in 40.51s

@abondar
Copy link
Member

abondar commented Jun 2, 2024

Duplicated these changes in #1636

@abondar abondar closed this Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError: 'Loop' object has no attribute '_selector' on tortoise.contrib.test
4 participants