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 censorship (naming model like "Model", if name != "Model" fix) #1298

Merged
merged 1 commit into from
Nov 28, 2022
Merged

Remove censorship (naming model like "Model", if name != "Model" fix) #1298

merged 1 commit into from
Nov 28, 2022

Conversation

gh0st-work
Copy link
Contributor

@gh0st-work gh0st-work commented Nov 27, 2022

Description

Moved ModelMeta field_map collecting block from under the condition if name != "Model":

Motivation and Context

Removes censorship. Whole app crashes if I name my model or meta-model like literally "Model".
Ex:

from tortoise import models


class Model(models.Model):
    ...

If you wanna know my opinion, better not to use __new__ and as litte as possible magic methods, you can use inspect.getmembers_static (link, python 3.11 only) in case of not calling __get__ and others.

How Has This Been Tested?

Tested in just CTRL+S and run, and reverse. Fixes the issue.

After successful fixing my issue, ran pytest.
Errors (i think, non mine):

platform win32 -- Python 3.11.0, pytest-7.2.0, pluggy-1.0.0

...

============================================================================================ short test summary info ============================================================================================= 
FAILED tests/test_queryset.py::TestQueryset::test_delete - tortoise.exceptions.OperationalError: near "ORDER": syntax error
FAILED tests/test_update.py::TestUpdate::test_bulk_update_json_value - tortoise.exceptions.OperationalError: unrecognized token: "{"
====================================================================== 2 failed, 1059 passed, 71 skipped, 4 xfailed, 117 warnings in 47.67s ======================================================================

Checklist:

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

@gh0st-work gh0st-work changed the title Remove censorship Remove censorship (naming model like "Model", if name != "Model") Nov 27, 2022
@gh0st-work gh0st-work changed the title Remove censorship (naming model like "Model", if name != "Model") Remove censorship (naming model like "Model", if name != "Model" fix) Nov 27, 2022
@gh0st-work gh0st-work changed the title Remove censorship (naming model like "Model", if name != "Model" fix) Remove censorship(naming model like "Model", if name != "Model" fix) Nov 27, 2022
@gh0st-work gh0st-work changed the title Remove censorship(naming model like "Model", if name != "Model" fix) Remove censorship (naming model like "Model", if name != "Model" fix) Nov 27, 2022
@gh0st-work gh0st-work changed the title Remove censorship (naming model like "Model", if name != "Model" fix) Remove censorship (naming model like "Model", if name != "Model" fix) Nov 27, 2022
@long2ice long2ice merged commit 7f46d99 into tortoise:develop Nov 28, 2022
@long2ice
Copy link
Member

Thanks!

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.

2 participants