René's URL Explorer Experiment


Title: Saving Link Model with Extra fields fails · Issue #339 · fastapi/sqlmodel · GitHub

Open Graph Title: Saving Link Model with Extra fields fails · Issue #339 · fastapi/sqlmodel

X Title: Saving Link Model with Extra fields fails · Issue #339 · fastapi/sqlmodel

Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I already searched in Google "How to X in...

Open Graph Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I...

X Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated searc...

Opengraph URL: https://github.com/fastapi/sqlmodel/issues/339

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Saving Link Model with Extra fields fails","articleBody":"### First Check\r\n\r\n- [X] I added a very descriptive title to this issue.\r\n- [X] I used the GitHub search to find a similar issue and didn't find it.\r\n- [X] I searched the SQLModel documentation, with the integrated search.\r\n- [X] I already searched in Google \"How to X in SQLModel\" and didn't find any information.\r\n- [X] I already read and followed all the tutorial in the docs and didn't find an answer.\r\n- [X] I already checked if it is not related to SQLModel but to [Pydantic](https://github.com/samuelcolvin/pydantic).\r\n- [X] I already checked if it is not related to SQLModel but to [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\r\n\r\n### Commit to Help\r\n\r\n- [X] I commit to help with one of those options 👆\r\n\r\n### Example Code\r\n\r\n```python\r\n# Models\r\n\r\nclass AssemblyEPDLink(SQLModel, table=True):\r\n    assembly_id: Optional[str] = Field(default=None, foreign_key=\"assembly.id\", primary_key=True)\r\n    epd_id: Optional[str] = Field(default=None, foreign_key=\"epd.id\", primary_key=True)\r\n    conversion_factor: float = 1.0\r\n\r\n    assembly: \"Assembly\" = Relationship(back_populates=\"layer_links\")\r\n    epd: \"EPD\" = Relationship(back_populates=\"assembly_links\")\r\n\r\n\r\nclass Assembly(SQLModel, table=True):\r\n    \"\"\"Assembly database class\"\"\"\r\n\r\n    id: Optional[str] = Field(default_factory=string_uuid, primary_key=True)\r\n    name: str = Field(index=True)\r\n    category: str\r\n    life_time: float = 50\r\n    meta_fields: dict = Field(default=dict, sa_column=Column(JSON), nullable=False)\r\n    unit: str = \"M2\"\r\n    conversion_factor: float = 1.0\r\n\r\n    layer_links: List[AssemblyEPDLink] = Relationship(back_populates=\"assembly\")\r\n\r\n\r\nclass EPD(SQLModel, table=True):\r\n    \"\"\"EPD database class\"\"\"\r\n\r\n    id: Optional[str] = Field(default_factory=string_uuid, primary_key=True)\r\n    name: str = Field(index=True)\r\n    category: str\r\n    gwp_by_phases: dict = Field(default=dict, sa_column=Column(JSON), nullable=False)\r\n    version: str\r\n    expiration_date: date\r\n    date_updated: date\r\n    source: str\r\n\r\n    assembly_links: List[AssemblyEPDLink] = Relationship(back_populates=\"epd\")\r\n\r\n# Strawberry Mutation\r\n@strawberry.type\r\nclass Mutation:\r\n    @strawberry.mutation(permission_classes=[IsAuthenticated])\r\n    async def add_assembly(\r\n        self,\r\n        info: Info,\r\n        name: str,\r\n        category: str,\r\n        life_time: float | None = 50,\r\n        meta_fields: Optional[JSON] = None,\r\n        layers: Optional[JSON] = None,\r\n        conversion_factor: float | None = 1,\r\n    ) -> GraphQLAssembly:\r\n\r\n        if meta_fields is None:\r\n            meta_fields = {}\r\n\r\n        session = info.context.get(\"session\")\r\n\r\n        assembly = Assembly(\r\n            name=name,\r\n            category=category,\r\n            life_time=life_time,\r\n            conversion_factor=conversion_factor,\r\n            meta_fields=meta_fields,\r\n        )\r\n\r\n        if layers:\r\n            query = select(EPD).where(col(EPD.id).in_([layer.get(\"id\") for layer in layers]))\r\n            epds = await session.exec(query)\r\n            epds = epds.all()\r\n\r\n            for epd in epds:\r\n                link = AssemblyEPDLink(assembly=assembly, epd=epd, conversion_factor=2)\r\n                session.add(link)\r\n        else:\r\n            session.add(assembly)\r\n            \r\n        await session.commit()\r\n        await session.refresh(assembly)\r\n\r\n        return assembly\r\n```\r\n\r\n\r\n### Description\r\n\r\n* I start my test\r\n* Set up a blank database and run `SQLModel.metadata.create_all(bind=engine)`\r\n* I create three EPDs and save them to the database\r\n* Then I post a new mutation to create a new Assembly with those EPDs in \"layers\"\r\n* When I try to commit the AssemblyEPDLink to the session the database throws an error:\r\n  *  `'asyncpg.exceptions.NotNullViolationError': null value in column \"assembly_id\" of relation \"assemblyepdlink\" violates not-null constraint`\r\n\r\n### Operating System\r\n\r\nLinux\r\n\r\n### Operating System Details\r\n\r\nUbuntu 22.04\r\n\r\n### SQLModel Version\r\n\r\n0.0.6\r\n\r\n### Python Version\r\n\r\n3.10\r\n\r\n### Additional Context\r\n\r\nI have tried to follow the steps outlined in the [docs](https://sqlmodel.tiangolo.com/tutorial/many-to-many/link-with-extra-fields/), adapted to my situation, but somehow the link model doesn't want to save to the database.\r\n\r\nWhen I create an Assembly without a link model everything works fine.\r\n\r\nI have a setup with FastAPI, Strawberry, SQLModel and postgres.","author":{"url":"https://github.com/ocni-dtu","@type":"Person","name":"ocni-dtu"},"datePublished":"2022-05-12T13:18:51Z","url":"https://github.com/fastapi/sqlmodel/issues/339"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:657965b3-9b5f-3360-6a3e-d86c5e3533c8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id97C2:306EC8:39F26B:524D75:6AFE04D0
html-safe-nonce82bb4d1731a468e2023d4994c6de2ebc99784032c617a99e162bb9f849737fb2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0MyOjMwNkVDODozOUYyNkI6NTI0RDc1OjZBRkUwNEQwIiwidmlzaXRvcl9pZCI6IjM4MzI2NDgxMDA2NzY5MDcwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac514201872b83e1d83e530235ce77844838c3470031ef20fce00615264f64a22c
hovercard-subject-tagissue:1233973980
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fastapi/sqlmodel/339/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b14af66530706dce5e50e992744f2de275f0c001c8724c8a2af62977d655d934/fastapi/sqlmodel/issues/339
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b14af66530706dce5e50e992744f2de275f0c001c8724c8a2af62977d655d934/fastapi/sqlmodel/issues/339
og:image:altFirst Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameocni-dtu
hostnamegithub.com
expected-hostnamegithub.com
None86d46ece7c3d9b0562692f81a135cb55ad6a1c82c93ab1ac874d2f1b46b28958
turbo-cache-controlno-preview
go-importgithub.com/fastapi/sqlmodel git https://github.com/fastapi/sqlmodel.git
octolytics-dimension-user_id156354296
octolytics-dimension-user_loginfastapi
octolytics-dimension-repository_id399495186
octolytics-dimension-repository_nwofastapi/sqlmodel
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id399495186
octolytics-dimension-repository_network_root_nwofastapi/sqlmodel
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5c18e6799976b7bc2f21178024289bb98edbcc85
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/fastapi/sqlmodel/issues/339#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffastapi%2Fsqlmodel%2Fissues%2F339
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffastapi%2Fsqlmodel%2Fissues%2F339
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=fastapi%2Fsqlmodel
Reloadhttps://github.com/fastapi/sqlmodel/issues/339
Reloadhttps://github.com/fastapi/sqlmodel/issues/339
Reloadhttps://github.com/fastapi/sqlmodel/issues/339
fastapihttps://github.com/fastapi
sqlmodelhttps://github.com/fastapi/sqlmodel
Codehttps://github.com/fastapi/sqlmodel
Issues1 (1)https://github.com/fastapi/sqlmodel/issues
Pull requests53 (53)https://github.com/fastapi/sqlmodel/pulls
Discussionshttps://github.com/fastapi/sqlmodel/discussions
Actionshttps://github.com/fastapi/sqlmodel/actions
Projectshttps://github.com/fastapi/sqlmodel/projects
Security and qualityhttps://github.com/fastapi/sqlmodel/security
Insightshttps://github.com/fastapi/sqlmodel/insights
https://github.com/fastapi/sqlmodel
New issuehttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/339
New issuehttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/339
Saving Link Model with Extra fields failshttps://github.com/fastapi/sqlmodel/issues/339#top
questionFurther information is requestedhttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22question%22
https://github.com/ocni-dtu
ocni-dtuhttps://github.com/ocni-dtu
on May 12, 2022https://github.com/fastapi/sqlmodel/issues/339#issue-1233973980
Pydantichttps://github.com/samuelcolvin/pydantic
SQLAlchemyhttps://github.com/sqlalchemy/sqlalchemy
docshttps://sqlmodel.tiangolo.com/tutorial/many-to-many/link-with-extra-fields/
ocni-dtuhttps://github.com/ocni-dtu
questionFurther information is requestedhttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22question%22
on May 12, 2022https://github.com/fastapi/sqlmodel/issues/339#event-6598313385
ocni-dtuhttps://github.com/ocni-dtu
on May 12, 2022https://github.com/fastapi/sqlmodel/issues/339#event-6598334072
https://github.com/ocni-dtu
ocni-dtuhttps://github.com/ocni-dtu
on May 17, 2022https://github.com/fastapi/sqlmodel/issues/339#issuecomment-1128627583
Tutorial 003https://github.com/tiangolo/sqlmodel/blob/main/docs_src/tutorial/many_to_many/tutorial003.py
https://github.com/ocni-dtu
ocni-dtuhttps://github.com/ocni-dtu
on May 17, 2022https://github.com/fastapi/sqlmodel/issues/339#issuecomment-1128630676
https://github.com/ocni-dtu
ocni-dtuhttps://github.com/ocni-dtu
on May 17, 2022https://github.com/fastapi/sqlmodel/issues/339#issuecomment-1128701534
https://github.com/ocni-dtu
ocni-dtuhttps://github.com/ocni-dtu
on May 17, 2022https://github.com/fastapi/sqlmodel/issues/339#issuecomment-1128703632
#322https://github.com/fastapi/sqlmodel/pull/322
ocni-dtuhttps://github.com/ocni-dtu
completedhttps://github.com/fastapi/sqlmodel/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on May 17, 2022https://github.com/fastapi/sqlmodel/issues/339#event-6623281137
https://github.com/fullstack-spiderman
fullstack-spidermanhttps://github.com/fullstack-spiderman
on May 26, 2022https://github.com/fastapi/sqlmodel/issues/339#issuecomment-1138621610
https://github.com/ocni-dtu
ocni-dtuhttps://github.com/ocni-dtu
on May 29, 2022https://github.com/fastapi/sqlmodel/issues/339#issuecomment-1140431648
https://github.com/fullstack-spiderman
fullstack-spidermanhttps://github.com/fullstack-spiderman
on May 30, 2022https://github.com/fastapi/sqlmodel/issues/339#issuecomment-1140774743
@ocni-dtuhttps://github.com/ocni-dtu
Sign up for freehttps://github.com/signup?return_to=https://github.com/fastapi/sqlmodel/issues/339
Sign in to commenthttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/339
questionFurther information is requestedhttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22question%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.