schema_helpers BUGFIX circular dependence check
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 52471d9..5415c28 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -929,11 +929,11 @@
         } else if (*mod && !revision && ((*mod)->latest_revision & LYS_MOD_LATEST_REV)) {
             (*mod)->latest_revision |= LYS_MOD_LATEST_SEARCHDIRS;
         }
-    } else {
-        /* We have module from the current context, circular check. */
-        LY_CHECK_RET(lys_check_circular_dependency(ctx, mod));
     }
 
+    /* Checking the circular dependence of imported modules. */
+    LY_CHECK_RET(lys_check_circular_dependency(ctx, mod));
+
     return LY_SUCCESS;
 }
 
diff --git a/tests/utests/basic/test_context.c b/tests/utests/basic/test_context.c
index 41efcaf..ce262ff 100644
--- a/tests/utests/basic/test_context.c
+++ b/tests/utests/basic/test_context.c
@@ -303,6 +303,7 @@
 test_imports(void **state)
 {
     struct lys_module *mod1, *mod2, *import;
+    char *str;
 
     /* use own context with extra flags */
     ly_ctx_destroy(UTEST_LYCTX);
@@ -342,6 +343,18 @@
     assert_int_equal(1, import->implemented);
     assert_string_equal("2019-09-18", import->revision);
     assert_null(ly_ctx_get_module(UTEST_LYCTX, "a", "2019-09-17"));
+    ly_ctx_destroy(UTEST_LYCTX);
+
+    /* check of circular dependency */
+    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS | LY_CTX_NO_YANGLIBRARY, &UTEST_LYCTX));
+    str = "module a {namespace urn:a; prefix a;"
+            "import b {prefix b;}"
+            "}";
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
+    str = "module b { yang-version 1.1; namespace urn:b; prefix b;"
+            "import a {prefix a;}"
+            "}";
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
 }
 
 static void