Comments (5)
Hi
Disregarding source_field
is actually not desired behaviour and I think I will try to fix it soon, but fixing it is a little more complex than I would like it to be, cause some parts of code at the moment relies on the fact that {}_id
field presence is guaranteed for every FK field.
from tortoise-orm.
@godstopme Could you please provide description of database schema for your case, your models for this schema (write models the way you think they should work) and show examples of desired behaviour?
from tortoise-orm.
Here's an stripped down example:
class Task(models.Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=10)
class Server(models.Model):
id = fields.IntField(pk=True)
label = fields.CharField(max_length=64)
class ExecutionEntry(models.Model):
class Meta:
unique_together = ('task', 'server')
executed_at = fields.DatetimeField()
task = fields.ForeignKey('models.Task', related_name='history', source_field='task')
server = fields.ForeignKey('models.Server', related_name='history', source_field='server')
In this case, the execution_entry
table is a join table with some extra metadata, and rather that task_id
and server_id
as the fields, they are task
and server
(because existing database).
I was going to submit a patch to fix this, but then I saw the comment that it is more complicated than I thought the fix to be. I don't see how it's complicated in the source code, so I'd like to know what I'm missing. This bug is a showstopper for me being able to use this library (and contribute to it as needed).
from tortoise-orm.
A lot of the complication is taken away by #122, which now handles all PK's via a generic way, which would make this much more reliable to implement.
If you want to go ahead and implement this, please do :-)
Please base it on the #122 branch, and then rebase with master once that is merged (It appears fully functional, just missing out on some tests).
from tortoise-orm.
Ok, I tried to have a go at this, and yes, I have a version that passes naïve tests, but it pollutes the single namespace per model.
so, e.g.
one = fields.IntField(source_field='two')
two = fields.CharField(max_length=10, source_field='one')
will break.
The solution would be to break Instance construction up into a from-python and a from-db, and have each of those constructors use different namespaces.
from tortoise-orm.
Related Issues (20)
- When creating objects via bulk_create with ignore_confilcts=False, an exception does not fire, the program simply stops execution, you have to wrap it in an exception handler and only then it catches the error, can you fix it? So that raise pops up in case of an exception by itself
- ValuesQuery execution fails when using select_related()
- When using update_or_create in the presence of concurrent requests, it can lead to deadlocks.
- MSSQLSchemaGenerator does not support creating tables in non-default (dbo) database schemas
- Question about signals in model inheritance
- Group by for many to many table problem
- blacksheep example unittest error
- Unittest failed after upgrade pydantic to v2.5
- timezone bug
- How to translate MySQL code with two primary keys to Tortoise?
- How tortoise implements the same functionality as SerializerMethodField in DRF?
- How can I add a virtual property to Model? and it can be set in controller.
- How to handle the same table self-join subquery
- Decimal field represented in scientific notation when using pydantic_model_creator
- Error on schema generation with several relations
- Optional parameter in pydantic_model_creator does not work after upgrading to pydantic v2 HOT 1
- [BUG:PEP563] tortoise.contrib.pydantic.utils.get_annotations uses incorrect global namespace
- How can i print sql with register_tortoise() in fastapi?
- Default timeout unknown HOT 1
- If datetimefield is not timezone-aware get_or_create fails UNIQUE constraint. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tortoise-orm.